astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Cropping text issue fix suggestion #117

Open doridori opened 10 years ago

doridori commented 10 years ago

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.

saifc commented 10 years ago

Hi,

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

doridori commented 10 years ago

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

saifc commented 10 years ago

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

doridori commented 10 years ago

Apologies :)

saifc commented 10 years ago

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

midaslefkowitz commented 9 years ago

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);
}
oatpano commented 7 years ago

@midaslefkowitz Thanks a lot.