Wirelessly how to implement sliding navigation

Source: Internet
Author: User
<span id="Label3"></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">Navigation is</span> <span style="font-size:14px;font-family:arial, helvetica, sans-serif;color:rgb(0,112,192);">Mobile Apps</span> <span style="font-size:14px;font-family:arial, helvetica, sans-serif;">one of the most important aspects of the user experience is that it plays a critical role in whether it is good or bad. Good navigation makes an app easier to use and lets users get started Quickly. conversely, Poor app navigation can be annoying and user-forsaken. To create a smooth user navigation experience, we have to rely on one of the most common features of Smartphones: Touch. </span></p></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">Touch changing the application view is now one of the most popular navigation designs. In this blog, we will go through the necessary steps to achieve horizontal sliding navigation within the app.</span></p></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">This article uses the code first method without Hesitation. Let's take a look at the main code snippets that need to be done for sliding Navigation.</span></p></p><pre class="brush:cpp;toolbar:false"><span style= "font-family:arial;font-size:14px;" >public class MainActivity extends Activity {      sectionspageradapter msectionspageradapter;    viewpager mviewpager;       @Override     protected void oncreate (bundle  Savedinstancestate)  {        super.oncreate (savedInstanceState);         setcontentview (r.layout.activity_main);          msectionspageradapter = new sectionspageradapter ( Getfragmentmanager ());        mviewpager =  (ViewPager)   Findviewbyid (r.id.pager);         mviewpager.setadapter ( msectionspageradapter);    }      @Override      publiC boolean oncreateoptionsmenu (menu menu)  {         Getmenuinflater (). Inflate (r.menu.main, menu);        return  true;    }      @Override     public  boolean onoptionsitemselected (menuitem item)  {         Int id = item.getitemid ();        if  (id ==  r.id.action_settings)  {             return true;        }         return super.onoptionsitemselected (item);    }      public class sectionspageradapter extends fragmentpageradapter {          public sectionspageradapter (fragmentmanager fm)  {             super (fm);        }           @Override         public  fragment getitem (int position)  {             switch  (position)  {                 case 0:                     return new moviesfragment ();                 case 1:                      Return new tvshowsfragmeNT ();                 case  2:                     return new songsfragment ();             }            return null;         }         @ Override        public int getcount ()  {             // Show 3 total pages.             return 3;         }    }}</span></pre><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">Our main activity contains the Viewpager component, which encapsulates several different menu screens with a different fragment on each Screen. The first thing we want to do is declare a fragmentpageradapter and use it to switch between the unused menu Fragment. As you can see in the code above, we declare a sectionspageradapter, which inherits from the Fragmentpageradaper class. It is then instantiated in the OnCreate method.</span></p></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">For the Sectionspageradapter class, you need to override two METHODS. The first method is the GetCount () method, which returns the number of fragment that are Navigated. The second and most GetItem () method, which is used to instantiate and return the associated fragment, is displayed based on its position in the MENU.</span></p></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb (255,255,255); font-family:Arial , Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px; "><span style="font-size:14px;font-family:arial, helvetica, sans-serif;" these different menu fragment must inherit the class and then populate their own layouts , let's take a look at one of these classes: < span> </span></p></p><pre class="brush:cpp;toolbar:false"><pre class="brush:cpp;toolbar:false"><span style= "font-family:arial;font-size:14px;" >public class moviesfragment extends fragment {     @ Override    public view oncreateview (layoutinflater inflater,  viewgroup container,                              Bundle  Savedinstancestate)  {        View rootView =  Inflater.inflate (r.layout.movies_fragment, container, false);         return rootview;    }}</span> </pre></pre><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb (255,255,255); font-family:Arial , Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px; "><span style="font-size:14px;font-family:arial, helvetica, sans-serif;" and put these together for our < span> <span style=" font-size:14px;font-family:arial, helvetica, Sans-serif;color:rgb (0,112,192); "> Android app </span> <span style="font-size:14px;font-family:arial, helvetica, sans-serif;"> Create a very intuitive sliding navigation. Our hard-working native ads can make the application profitable without compromising the user Experience. Quickly integrate native, in-stream, and customizable ad units, where you can check out the native ads sdk, </span> </span></p></p><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><p style="margin-bottom:20px;padding:0px;white-space:normal;background-color:rgb(255,255,255);font-family:Arial, Helvetica, sans-serif;font-size:12px;border:0px;margin-top:0px;"><span style="font-size:14px;font-family:arial, helvetica, sans-serif;">Here you can get the full source code for this tutorial:</span> <span style="font-size:14px;font-family:arial, helvetica, sans-serif;color:rgb(0,112,192);">Swipenavigationexample</span> <span style="font-size:14px;font-family:arial, helvetica, sans-serif;">. </span></p></p><p><p><br></p></p><p><p>Wirelessly how to implement sliding navigation</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.