設定tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
手機直立顯示,Tab在畫面上看起來很正常,超出螢幕的寬度,可以用scroolable解。
但
當手機橫置顯示時,Tab的總寬度小於螢幕寬度太多,造成視覺上很奇怪,如何解?
答案:
As I didn't find why does this behaviour happen I have used the following code:
float myTabLayoutSize = 360;
if (DeviceInfo.getWidthDP(this) >= myTabLayoutSize ){
tabLayout.setTabMode(TabLayout.MODE_FIXED);
} else {
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
Basically, I have to calculate manually the width of my tabLayout and then I set the Tab Mode depending on if the tabLayout fits in the device or not.
The reason why I get the size of the layout manually is because not all the tabs have the same width in Scrollable mode, and this could provoke that some names use 2 lines as it happened to me in the example.
在不同顯示下,使用不同的顯示方式。
上述解答,應需加
app:tabGravity="fill"
沒有留言:
張貼留言