PagerSlidingTabStrip
PagerSlidingTabStrip copied to clipboard
Cropping text issue fix suggestion
Hi,
I noticed when I run my app on a tablet device and all the tabs can fit without scrolling on some devices if one of the tabs had a longer text label it would crop the text size. This seems to be due to the PagerSlidingTabStrip lines below
defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
which due its size being set as 0 when expanded will only work out the sizing based on the tab padding set. Using
defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
expandedTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1.0f);
works much better for me. I cant see any downside of this approach but am suggesting it as an improvement on the current codebase.
Hi,
I am experiencing the same issue.Please include the fix.
Not meaning to be rude but I have literally included it in the post above
I know , i was talking to the owner so he could include it in the next release
Apologies :)
It's OK,no need to apologize man :)
If you dont want to fork the library itself you can implement this minihack (where tabstrip is a reference to your PagerSlidingTabStrip):
LinearLayout tabsContainer = (LinearLayout) tabStrip.getChildAt(0);
for (int i=0; i < tabsContainer.getChildCount(); i++) {
TextView tab = (TextView)tabsContainer.getChildAt(i);
tab.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
}
You might also want to add left and right padding to the tabs while you are at it. in which case the code would be (I added an 8px padding):
LinearLayout tabsContainer = (LinearLayout) tabStrip.getChildAt(0);
for (int i=0; i < tabsContainer.getChildCount(); i++) {
TextView tab = (TextView)tabsContainer.getChildAt(i);
tab.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
tab.setPadding(8,0,8,0);
}
@midaslefkowitz Thanks a lot.