Android TabLayout - 标签向左折叠

时间:2015-08-03 15:28:45

标签: android android-design-library android-tablayout

我已经实现了一个有效的TabLayout。这是xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:elevation="4dp">

    <android.support.design.widget.TabLayout
        android:id="@+id/club_sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@android:color/white"
        app:tabTextColor="#EEEEEE"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white"/>

</LinearLayout>

然后我用4个标签加载它。然后会发生的是,标签不会在宽度上填充屏幕,但它们是从左侧“线性”添加的,因此标签栏的右端有空白区域。

我尝试tabMode="fixed",但这导致标题标题分为两行,例如:

CALEND
AR

有人有同样的问题并解决了吗?感谢。

1 个答案:

答案 0 :(得分:1)

使用app:tabMode="fixed"代替可滚动。

编辑: - 用于更改标签布局中的文字大小

修复标签中的文字大小

<style name="MyTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse">
   <item name="android:textSize">14sp</item>
</style>

app:tabTextAppearance="@style/MyTabLayoutTextAppearance"