ActionBar Tabs - Fixed and Scrollable?

2019-03-15 01:53发布

In the Android Design Guidelines it states that "There are two types of tabs: fixed and scrollable."

I can't find any documentation in the ActionBar documentation to support the ability to specify either type of tabs.

How do you specify a tab group to be fixed or scrollable? If you can't, what governs whether the tabs are fixed or scrollable exactly?

2条回答
神经病院院长
2楼-- · 2019-03-15 02:17

It's worth noting that the setting

    android:showAsAction

will also have an effect on how tabs are shown, at least in 4.0+ devices. Setting

        <item name="android:showAsAction">always</item>

as part of a theme will result in all tabs being given equal spacing on the screen, without scrolling, if space is available to do so.

查看更多
Bombasti
3楼-- · 2019-03-15 02:35

The number of tabs dictates whether the tab group is fixed or scrollable. For example, if you have one tab, they'll be fixed but if you have like six then they'll become scrollable because all six can't fit on one screen.

If you want to see it in action on a pre-3.0 device, download the Action Bar Sherlock sample and select Feature Toggles from the main list and then select "Tabs" as your navigation mode. Now you can add tabs to the bar and at first, they'll get smaller to cram them all in and then once you have enough you can scroll through them.

UPDATE: There is now a page on this in the official documentation that says "Fixed tabs are displayed with equal width, based on the width of the widest tab label. If there is insufficient room to display all tabs, the tab labels themselves will be scrollable." Read more here.

查看更多
登录 后发表回答