PagerSlidingTabStrip icon indicating copy to clipboard operation
PagerSlidingTabStrip copied to clipboard

Cropping text issue fix suggestion

Open doridori opened this issue 11 years ago • 7 comments

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.

doridori avatar Jul 18 '14 14:07 doridori

Hi,

I am experiencing the same issue.Please include the fix.

saifc avatar Jul 27 '14 19:07 saifc

Not meaning to be rude but I have literally included it in the post above

doridori avatar Jul 27 '14 19:07 doridori

I know , i was talking to the owner so he could include it in the next release

saifc avatar Jul 27 '14 20:07 saifc

Apologies :)

doridori avatar Jul 27 '14 23:07 doridori

It's OK,no need to apologize man :)

saifc avatar Jul 27 '14 23:07 saifc

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 avatar Jun 21 '15 20:06 midaslefkowitz

@midaslefkowitz Thanks a lot.

oatpano avatar Jan 27 '17 08:01 oatpano