Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ????

like image 923
kimkevin Avatar asked Jun 19 '14 08:06

kimkevin


2 Answers

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
like image 64
sonida Avatar answered Sep 21 '22 17:09

sonida


I solved this problem by myself. The problem is shouldExpand Attr doesn't work because our tabs are 5 so I can't. but when I set my tab count 4, it works and looks good. They filled with device screen width.

Anyway I changed this width size.

defaultTabLayoutParams  = new LinearLayout.LayoutParams(dm.widthPixels/your tab count, LayoutParams.MATCH_PARENT);

I hope it will be helpful and save your time.

like image 27
kimkevin Avatar answered Sep 20 '22 17:09

kimkevin