/**
* Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab
* labels and a larger number of tabs. They are best used for browsing contexts in touch
* interfaces when users don’t need to directly compare the tab labels.
*
* @see #setTabMode(int)
* @see #getTabMode()
*/
public static final int MODE_SCROLLABLE = 0;
# 1 楼答案
如果你想让标签占据整个屏幕,你需要为TabLayout分配app:tabGravity=“fill”。如果有三个标签,它将在屏幕范围内进行调整,如果超过三个,它将自动提供滚动功能
其余请参考完整的tablayout之旅链接
https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
# 2 楼答案
TabLayout
有一个名为tabMode
的字段。如果希望它可以滚动,那么设置为TabLayout.MODE_SCROLLABLE
这是完整的文件
我还建议你不要让模式滚动,除非你有至少6个标签