android - TabLayout 重心不起作用

标签 android android-layout android-tablayout

我有一个 TabLayout,我希望选项卡显示在屏幕中央。 下面是我的 TabLayout 的 XML。

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/white"
            app:tabGravity="center"
            app:tabIndicatorColor="@color/about_tab_selected"
            app:tabIndicatorHeight="4dp"
            app:tabMode="scrollable"
            app:tabPaddingEnd="20dp"
            app:tabPaddingStart="20dp"
            app:tabSelectedTextColor="@color/about_tab_selected"
            app:tabTextAppearance="@style/UGTabTextAppearance"
            app:tabTextColor="@color/about_tab_unselected" />

但是,我的选项卡仍然显示在左侧,我无法将它们置于 Activity 中心。

我得到的是这样的: enter image description here

我真正想要的是: enter image description here

有人可以告诉我我做错了什么吗?如果您需要有关 XML 其余部分的更多信息,请告诉我。

最佳答案

Tab 引力仅影响 MODE_FIXED。

一个可能的解决方案是将 layout_width 设置为 wrap_content 并将 layout_gravity 设置为 center_horizo​​ntal

关于android - TabLayout 重心不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43588653/

相关文章:

android - PagerTabStrip 和 TabLayout 的区别

Android Instrumentation 测试运行程序 : How to filter multiple test annotations

java - Android 广播接收器仅处于待机状态或应用程序不活动状态

android - 如何修复多个屏幕尺寸的应用程序

java - 从 Tablayout Fragment ( Android) 实现接口(interface)

android - ViewPager - 从 setOnTabSelectedListener 启动 Activity

android - 使用按钮单击和滚动进行水平页面交换 - Flutter

android - 内部类的返回值

android - 我怎样才能让我的按钮在 radiogroup 上居中?

java - 使用自定义 UI 显示相机 View