Text inside tabs of a TabLayout is not centered

Bir*_*ngh 6 android android-tablayout

I am using a TabLayout. I want full screen width to be filled by TabLayout, so I added app:tabGravity="fill". My problem is that now tab text is not centered. Here is a screenshot:

请参阅选项卡一下的粉红色条

The code of TabLayout is as follows:

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextColor="#d3d3d3"
        app:tabSelectedTextColor="#ffffff"
        app:tabIndicatorColor="#ff00ff"
        android:minHeight="?attr/actionBarSize"
        />
Run Code Online (Sandbox Code Playgroud)

I have seen many questions but none of them solves my problem. Any help is highly appreciated. For details I want to tell that I am trying this example. Device is running on Android 2.3.6 (API 10). Screen is 320x240.

Mez*_*oid 2

使用它来调整文本:

android:gravity="center" OR android:textAlignment="center"
Run Code Online (Sandbox Code Playgroud)

您应该创建一个自定义选项卡..您正在使用 tabLayout 的这些属性,这将不起作用...您上面提供的示例链接使用名为 custom_tab.xml 的文件。使用它来定义您的 textView 并将这些属性放入其中。

  • `android:gravity="center"` 和 `android:textAlignment="center"` 都不能解决这个问题。 (4认同)