RoShan Shan
RoShan Shan

Reputation: 2954

Centralize TabLayout

I want to centralize TabLayout when app:tabMode="scrollable"

My 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>

With that layout. Tablayout like this (but all tabs are aligned left):

enter image description here

if app:tabMode="fixed", the text in the center tab will have smaller size than the others.

enter image description here

So. I want make the same size of all text in TabLayout if app:tabMode="fixed" (all tabs are aligned central). If app:tabMode="scrollable", I want to centralize tab(like tabMode fixed). Thanks

Upvotes: 1

Views: 322

Answers (2)

RoShan Shan
RoShan Shan

Reputation: 2954

I work around by adding padding, still in app:tabMode="fixed"

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

to TabLayout.

Upvotes: 0

Wilson Christian
Wilson Christian

Reputation: 650

SmartTabLayout library could help you having your tabs always in center.

Upvotes: 1

Related Questions