PagerTitleStrip Overlaps With Actual Content
I am using A custom viewpager with a PagerTitleStrip, both supported by the android compatibility package. As recommended I use it like this:
Solution 1:
How do you add views to ViewPager?
When I met the same problem, the cause was to add views with wrong position in my PagerAdapter implementation.
The bad code was like this.
viewPager.setAdapter(new PagerAdapter() {
@Override
public Object instantiateItem(ViewGroup pager, int position) {
View view = createView(position);
((ViewPager) pager).addView(view, position);
return view;
}
@Override
public void destroyItem (ViewGroup pager, int position, Object view) {
((ViewPager) pager).removeViewAt(position);
}
...
});
This code had been working, however, when I began to use PagerTitleStrip, the PagerTitleStrip view became the first child of the ViewPager, hence addView(view, 0)
broke the internal structure of the ViewPager.
It was fixed by replacing addView
and removeView
as below.
- addView(view, position) -> addView(view)
- removeViewAt(position) -> removeView((View) view)
Hope it helps!
Solution 2:
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.page_view, null);
((ViewPager) collection).addView(view);
getPageTitle(position);
return view;
}
Just remove index of addView method. it solve overlapping problem of strip.
Post a Comment for "PagerTitleStrip Overlaps With Actual Content"