Search code examples
androidpagerslidingtabstrip

PagerSlidingTabStrip making horizontalscrollview's width fixed


I'm using PagerSlidingTabStrip library in my application now. I have 5 tabs, so it's over screen width. so I have to scroll to see last tab.

I want to see all tabs on the screen and never wanna scroll to see other items.

I tried changing HorizontalScrollView to LinearLayout in PagerSlidingTabStrip.java but it's weird a little. Indicator moved bad.

// public class PagerSlidingTabStrip extends HorizontalScrollView

public class PagerSlidingTabStrip extends LinearLayout

and also I tried shouldExpand options is true. but it didn't work again.

app:pstsShouldExpand="true"

What can i do for this ????


Solution

  • I had exactly same problem but following code ,I found that if you need to set tabs shouldExpand you need to do it before setting viewpager to tabs.

    tabs = (PagerSlidingTabStrip) findViewById(R.id.slidingTabStrip);
    //Before  setting view pager
    
    tabs.setShouldExpand(true); //Works
    
    tabs.setViewPager(vpPager);
    
    //After setting view pager
    tabs.setShouldExpand(true); //Will not work