TabLayout中的单个选项卡未覆盖整个宽度

moh*_*hra 7 android androiddesignsupport

我用TabLayout创建了一个视图寻呼机.现在问题是,如果我有2个或更多选项卡,那么一切都很好.但如果我只有一个标签,那么它不会覆盖整个屏幕宽度.PFA xml布局

 <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed"
        style="@style/TabLayout"
        android:fillViewport="true"
        android:layout_below="@id/ssrToolbar"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sliding_tabs"
        android:layout_above="@+id/llButtonLayout"
        android:background="@android:color/white" />
Run Code Online (Sandbox Code Playgroud)

这里还有两张图片

单个标签

两个标签

Tik*_*iko 19

如果有人仍然感兴趣你应该在xml app:tabMaxWidth="big_number"中为TabLayout 添加这个属性 ,对于big_number,我选择了2000dp.如果您没有分配任何值,则默认实现会使用TAB_MIN_WIDTH_MARGIN值减去测量规格大小的宽度.