PagerSlidingTabStrip making horizontalscrollview's width fixed
Asked Answered
A

2

5

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

Aceves answered 19/6, 2014 at 8:55 Comment(0)
K
12

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
Kessiah answered 17/12, 2014 at 7:59 Comment(0)
A
3

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.

Aceves answered 27/6, 2014 at 6:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.