【问题标题】:Centralize TabLayout集中标签布局
【发布时间】:2017-04-10 14:28:13
【问题描述】:

app:tabMode="scrollable"时想集中TabLayout

我的TabLayout

<android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_gravity="center"
                android:background="@android:color/white"
                android:gravity="center"
                android:visibility="visible"
                app:tabGravity="fill"
                app:tabIndicatorHeight="0dp"
                app:tabMaxWidth="0dp"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/colorTabSelected"
                app:tabTextAppearance="@style/CustomTextStyle"
                app:tabTextColor="@color/colorTabNormal"></android.support.design.widget.TabLayout>

采用这种布局。像这样的标签布局(但所有标签都左对齐):

如果app:tabMode="fixed",中心选项卡中的文本将比其他文本小。

所以。如果app:tabMode="fixed"(所有选项卡都居中对齐),我想让 TabLayout 中的所有文本大小相同。如果app:tabMode="scrollable",我想集中标签(如tabMode fixed)。 谢谢

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    SmartTabLayout 库可以帮助您将标签始终居中。

    【讨论】:

    • 我以前用过,但我想要一些更简单的东西,比如 TabLayout。谢谢建议
    • 好的,没问题。
    【解决方案2】:

    我通过添加填充来解决问题,仍在app:tabMode="fixed"

    app:tabMode="fixed" app:tabPaddingEnd="1dp" app:tabPaddingStart="1dp"

    到 TabLayout。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多