【问题标题】:TabLayout tabItem tabGravity center not workingTabLayout tabItem tab重力中心不起作用
【发布时间】:2018-02-06 11:57:00
【问题描述】:

超过 5 个标签可以正常工作,但 3 个标签看起来不太好。
这是我的 TabLayout XML 代码:

 <android.support.design.widget.TabLayout
            android:gravity="center"
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/search_bar"
            android:fillViewport="false"
            app:tabGravity="center"
            app:tabIndicatorColor="@color/ThemeColor"
            app:tabIndicatorHeight="6dp"
            app:tabMode="scrollable"
            android:paddingBottom="2dp"
            android:background="@drawable/bottom_dotted_border"
            app:tabSelectedTextColor="@color/ThemeColor"
            app:tabTextAppearance="@style/TabLayoutTextStyle"
            app:tabTextColor="@color/White" />

problamatic tab desire tab

【问题讨论】:

标签: android xml android-tablayout


【解决方案1】:

只需更改此 app:tabMode="scrollable" app:tabMode="fixed" 在您的标签布局中

1. app:tabMode="fixed : 选项卡在你的选项卡布局中是固定的(当你的选项卡有很长的选项卡标题时它不好)

2。 tabMode:scrollable - 当你的标签有长标签时,你可以水平滚动标签

示例代码

<android.support.design.widget.TabLayout
        android:gravity="center"
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/search_bar"
        android:fillViewport="false"
        app:tabGravity="fill"
        app:tabMode="fixed"
        app:tabIndicatorColor="@color/ThemeColor"
        app:tabIndicatorHeight="6dp"
        android:paddingBottom="2dp"
        android:background="@drawable/bottom_dotted_border"
        app:tabSelectedTextColor="@color/ThemeColor"
        app:tabTextAppearance="@style/TabLayoutTextStyle"
        app:tabTextColor="@color/White" />

【讨论】:

  • app:tabMode="fixed" 将切断标签标题的长字符串。
  • 任何解决方案??请帮助我。
  • @MdAslamHossin 检查更新并使用app:tabGravity="fill"
【解决方案2】:

如果您使用tabMode:scrollable,只需将android:layout_width="match_parent" 修复为"wrap_content"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 2017-12-07
    • 2017-07-02
    • 2016-11-26
    • 1970-01-01
    相关资源
    最近更新 更多