Search code examples
androidtabsandroid-viewpagerpagerslidingtabstrip

PagerSlidingTabStrip shows wrong position of viewPager's item


I need to show the 2nd page of viewPager. After

viewPager.setCurrentItem(1);

it really shows the 2nd page. BUT PagerSlidingTabStrip shows the 3rd page... And then if I scroll to any direction - tabs update itself and look/switch correct. And this problem I see only at Nexus-4, but not at the Nexus-5, HTC ONE and other devices...


Solution

  • I've found the reason, why this is happening. In my code I added a margin to viewPager.

       final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
                .getDisplayMetrics());
       pager.setPageMargin(pageMargin);
    

    And if you remove this margin - you will solve this problem particular. I don't have other ways