"Andord true" slidemenu+viewpagerindictor double sliding sidebar + sliding navigation bar

Source: Internet
Author: User

Take Slidemenu to achieve the effect sidebar:

Room

Setcontentview is the layout that sets the main background

Setbehindcontentview is to set the layout of the left menu

Setsecondarymenu is to set the layout on the right


Setshadowwidth is to set the width of the shadow

Setbehindwidth is set valid pull-out width

SetMode is set to open the menu on both left and right


Use Viewpagerindictor to implement sliding navigation bar and page layout

The use of tabpageindicator to do sliding navigation bar

Viewpager do a sliding layout

The first thing to do is to set the navigation bar style

    <style name= "Homeuptheme" parent= "Android:Theme.Holo.Light.DarkActionBar" > <item name= "vpitabpagei Ndicatorstyle "> @style/customtabpageindicator</item> </style> <style name=" Customtabpageindic Ator "parent=" Widget.tabpageindicator "> <item name=" android:dividerpadding ">10dp</item> <i        TEM name= "Android:paddingleft" >20dp</item> <item name= "Android:paddingright" >20dp</item> <item name= "Android:paddingtop" >10dp</item> <item name= "Android:paddingbottom" >10dp</item&gt        ; <item name= "Android:textsize" >10pt</item> <item name= "android:textappearance" > @style/ customtabpageindicator.text</item> <item name= "Android:textcolor" > #000000 </item> <item Name= "Android:fadingedge" >horizontal</item> <item name= "Android:fadingedgelength" >8dp</item > <item name= "AndroiD:background "> @drawable/selectitle</item> <item name=" android:gravity ">center</item> </s Tyle>
In the Code
Viewpager inside can be set to load

Layout adapter Pageradapter overriding Instantiateitem method

Fragment adapter Fragmentstatepageradapter overriding method of Fragment GetItem ()

And finally connect the two.

Indicatorview.setviewpager (pager);

Full code:

public class Mainact extends slidingactivity {slidingmenu slidingmenu; Tabpageindicator Indicatorview; Viewpager Pager; @Overridepublic void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setbehindcontentview (R.layout.slide_behind); SetContentView ( R.layout.slide_main); slidingmenu = Getslidingmenu (); Slidingmenu.setbehindoffset (); Slidingmenu.setbehindwidth ( Slidingmenu.setsecondarymenu (R.layout.slide_second);//Slidingmenu.settouchmodeabove (SlidingMenu.LEFT_ right); Slidingmenu.setshadowwidth (+); Slidingmenu.setmode (slidingmenu.left_right); Indicatorview = ( Tabpageindicator) Findviewbyid (r.id.indicator);p ager = (Viewpager) Findviewbyid (R.id.pager);p Ager.setadapter (new Myadapter ());p Ager.setoffscreenpagelimit (8); Indicatorview.setontabreselectedlistener (new Ontabreselectedlistener () {@Overridepublic void ontabreselected (int position) {Toast.maketext (getapplicationcontext (), Position + "",. Show ();//TODO auto-generated method Stubpager.setcurrentitem (position);}}); Pager.setcurrentitem (0); Indicatorview.setviewpager (pager); indicatorview.setclickable (true);} Class Myadapter extends Pageradapter {@Overridepublic int getcount () {//TODO auto-generated method Stubreturn 8;} @Overridepublic charsequence getpagetitle (int position) {//TODO auto-generated method Stubreturn "--" + position + "--";} @Overridepublic void Destroyitem (ViewGroup container, int position, object object) {//TODO auto-generated method Stub (Vi Ewpager) container). Removeviewat (position); Super.destroyitem (container, Position, object);} @Overridepublic boolean isviewfromobject (View arg0, Object arg1) {//TODO auto-generated method Stubreturn arg0 = arg1;} @Overridepublic Object Instantiateitem (viewgroup container, int position) {//TODO auto-generated method Stubimageview im Ageview = new ImageView (Getapplicationcontext ()); Imageview.setimagebitmap (Bitmapfactory.decoderesource ( Getresources (), r.drawable.flower)); Container.addview (imageView); return IMageview;//return Super.instantiateitem (container, position);}} 



Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

"Andord true" slidemenu+viewpagerindictor double sliding sidebar + sliding navigation bar

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.