Using the latest Android Support Package v4 (December 2011), I’m trying to implement a ViewPager with a PagerTitleStrip to show the title of the three panes in my UI.
I’ve read the sparse docs and successfully created the title strip at the top of my view, using the following XML:
<android.support.v4.view.ViewPager
android:id="@+id/mypager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.view.PagerTitleStrip
android:layout_gravity="top"
android:id="@+id/titlestrip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true" />
</android.support.v4.view.ViewPager>
However, my view now has a “gap” at the bottom of the layout, with height precisely the same as the title strip. If I increase the size of the title strip at the top of the UI, the gap at the bottom of my view also enlarges. It’s as if there is a bug in PagerTitleStrip which is incorrectly placing the title strip at both the top and the bottom, even though it’s only displaying it at the top.
If I set layout_gravity to “bottom” instead of top, the strip shows correctly, i.e. at the bottom of the view without any strange artifacts at the top. And if I remove the title strip, the gap disappears.
Anyone have a solution to this, or seen it in their code as well?
When you add views to your view pager in instantiateItem, make sure you call addView(view), NOT addView(view, 0).
This fixed this issue for me.