How to make tab title alignment on left in TabLayout in Android

I can not align the tab headers on the left, inside my TabLayout. Headings are currently focused. This is what I want to achieve.

And this is what I have at the moment. The code I use is as follows:

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabTextColor="@color/white"
    app:tabSelectedTextColor="@color/white"
    app:tabIndicatorColor="@color/white"
    android:background="@color/slate_grey"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
+6
source share
4 answers

add app:tabMode="scrollable"to yours <TabLayout.../>and don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto"too.

For more information https://developer.android.com/reference/android/support/design/widget/TabLayout.html

+15

TabLayout wrap_content. .

+2

Aside from Elvis's answer, attributes app:tabPadding*can help you distribute (or normalize the length) tabs headers.

0
source

Add " tabPaddingEnd " and " tabMode = scrollable " to your TabLayout

 <android.support.design.widget.TabLayout
                app:tabGravity="fill"
                app:tabMode="scrollable"
                app:tabPaddingEnd="60dp"
                android:id="@+id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:textAlignment="textStart"
                app:tabSelectedTextColor="#000"
                app:tabIndicatorColor="#000"
                app:tabTextColor="#000" />
0
source

Source: https://habr.com/ru/post/1652442/


All Articles