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

Nexus 7截图 Nexus 4截图


当前回答

对我来说,下面的代码可以工作并且足够了。

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"/>

其他回答

<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"/>

对我来说,下面的代码可以工作并且足够了。

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"/>

为什么要这么忙? 只要把app:tabMode="scrollable"放在你的XML TabLayout中。 这是它。

请注意,您还需要设置

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

填满所有空间