How to stop headings on Android tabs from wrapping in the middle of a word?

I have a multi-tab layout. What happens is that in landscape orientation the layout wraps the text used in the headings of the tabs, but not in the word, but in the middle of the word! So a name like:

Description 

It looks good in the portrait, but in the landscape it looks like this:

 Desc ript ion 

I do not define any word wraps or style attributes for the text. I would suggest that the layout will have more space in landscape mode than in portrait mode, so this makes no sense. I would appreciate any advice on what to see.

+4
source share
4 answers

Late answer, but Google brought me here, so that might be useful yet.

You can choose to scroll through the tabs, which I think are preferable to change the font size.

Application: tabMode = "scroll"

 <android.support.design.widget.TabLayout android:id="@+id/tablayout_id" android:layout_height="wrap_content" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" app:tabMode="scrollable" > 
+10
source
  • Do you use the same layout file for landscape and portrait?
  • Is the width of your tabs set to wrap_content ?
  • Try setting singleLine="true" in the tab text
  • Does the width of the tab graph increase when the landscape changes?
  • Do you use custom background on tabs, and if so, are there nine patches?

Although TBH I usually use RadioGroup and FrameLayout to achieve tabs, because it provides more control (you cannot change the tab strip retrieved before 2.2, and using this method, your tabs can be separated from the contents of the tab so you can put either there. Where you want).

0
source

OK, we managed to fix it. I had to reduce the font size by 1pt and reduce the left + right tab on the tabs. We also noticed that the tabs in the landscape were the same size, but they weren’t in the portrait, so obviously we had fill_parent instead of wrap_content somewhere. The patch seems to work for both 7 "and 10" tablets. Thanks for the help.

0
source

You can control it,

Override this class in the project ActionBarSherlock./ActionbarSherlock/src/com/actionbarsherlock/internal/widget/ScrollingTabContainerView.java

 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) { //comment this line // super.onMeasure(MeasureSpec.makeMeasureSpec(mParent.mMaxTabWidth, MeasureSpec.EXACTLY),heightMeasureSpec); //now do nothing , override by me for ActionBarTabs not rezize never //this method manage the size tabs, if you want you can count caracters to resize the size width } } 
0
source

Source: https://habr.com/ru/post/1344929/


All Articles