How to stick Title for ViewPager to the TOP. PagerTitleStrip Android -
i have strange me issue viewpager.
i need add pagertitlestrip viewpager , put on top. try put layout_gravity = "top", reserves space on "bottom" , show title string on "top"!
when put gravitity "bottom", displays correctly.
here screens
top - http://clip2net.com/s/4wdduj
bottom - http://clip2net.com/s/4wdd8k
viewpager - green pagertitlestrip - blue pager content match_parrent - red
please me understand why happens. how stick top , dont have green space on bottom?
thank you.
here xml pager:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v4.view.viewpager android:id="@+id/pagertelefooninfo" android:layout_width="wrap_content" android:background="#1af00f" android:layout_height="wrap_content" > <android.support.v4.view.pagertitlestrip android:id="@+id/pagertitlestrip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#3affef" android:layout_gravity="top" > </android.support.v4.view.pagertitlestrip> </android.support.v4.view.viewpager> </linearlayout>
here activity:
public class apager extends activity { viewpager pager; pageradapter pageradapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_pager); pager = (viewpager) findviewbyid(r.id.pager); pageradapter = new mypageradapter(); pager.setadapter(pageradapter); } private class mypageradapter extends pageradapter { public int getcount() { return 1; } public object instantiateitem(view collection, int position) { layoutinflater inflater = (layoutinflater) collection.getcontext() .getsystemservice(context.layout_inflater_service); view view = null; switch (position) { case 0: view = inflater.inflate(r.layout.fragment1, null); ((viewpager) collection).addview(view, 0); break; case 1: view = inflater.inflate(r.layout.fragment2, null); ((viewpager) collection).addview(view, 0); break; } return view; } @override public charsequence getpagetitle(int position) { return "title " + position; } public void destroyitem(view arg0, int arg1, object arg2) { ((viewpager) arg0).removeview((view) arg2); } public boolean isviewfromobject(view arg0, object arg1) { return arg0 == ((view) arg1); } public parcelable savestate() { return null; } // public int getitemposition(object object) { return position_none; } } }
take @ viewpager layout set have works correctly strip on top:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1"> <android.support.v4.view.pagertitlestrip android:id="@+id/pager_title_strip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textcolor="#fff" android:paddingtop="4dp" android:paddingbottom="4dp"/> </android.support.v4.view.viewpager>
Comments
Post a Comment