我已经设置选项卡为UPDATE 29/05/2015这篇文章。在我的Nexus 4手机上,标签是全宽的,但在Nexus 7平板电脑上,它位于中间,没有覆盖全屏宽度。

Nexus 7截图 Nexus 4截图


当前回答

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />

为我工作。这里还有xmlns:app="http://schemas.android.com/apk/res-auto"

其他回答

要强制制表符占用全宽度(分割成相等的大小),将以下应用到TabLayout视图:

TabLayout tabLayout = (TabLayout) findViewById(R.id.your_tab_layout);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_FIXED);

从Kaizie那里借用的一个“更简单”的答案只是在你的TabLayout xml中添加app:tabMaxWidth="0dp":

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />

请注意,您还需要设置

  app:tabPaddingStart="-1dp"
  app:tabPaddingEnd="-1dp"

填满所有空间

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />

为我工作。这里还有xmlns:app="http://schemas.android.com/apk/res-auto"

就这么做了,效果很好

<com.google.android.material.tabs.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabMaxWidth="0dp"/>