TabLayout重心无法正常工作 [英] TabLayout gravity center is not working

查看:96
本文介绍了TabLayout重心无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TabLayout,我希望在其中将选项卡显示在屏幕中央. 以下是我的TabLayout的XML.

I have a TabLayout, where I want the tabs to be displayed in the center of the screen. Below is the XML for my TabLayout.

<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" />

但是,我的标签仍然显示在左侧,并且我无法在活动"中将其居中.

However, my Tabs are still displayed to the left, and I'm unable to center them in the Activity.

我得到的是:

我真正想要的是:

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

Can somebody please tell me what I'm doing wrong here? If you need additional information regarding the rest of the XML, please let me know.

推荐答案

标签重力仅影响MODE_FIXED.

Tab gravity only effects MODE_FIXED.

一种可能的解决方案是将您的layout_width设置为wrap_content,而layout_gravity设置为center_horizo​​ntal

One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal

这篇关于TabLayout重心无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆