Reputation: 161
I can't seem to align my tab titles to the left, inside my TabLayout. At the moment, the titles are centered. Here is what I want to achieve.
And this is what I have at the moment. The code I'm using 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>
Upvotes: 16
Views: 13126
Reputation: 41
There is a way out .... wrap your Tablayout with a Relative layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="169dp"
android:layout_height="?actionBarSize"
android:layout_alignParentStart="true"
android:layout_marginEnd="120dp"
android:textAllCaps="false"
app:tabIndicator="@drawable/tab_indicator"
app:tabIndicatorColor="#ffffff"
app:tabIndicatorFullWidth="false"
app:tabIndicatorGravity="bottom"
app:tabPaddingEnd="-3dp"
app:tabPaddingStart="-6dp"
app:tabSelectedTextColor="#ffffff"
app:tabTextColor="#717171" />
</RelativeLayout>
Upvotes: 2
Reputation: 209
Try app:tabPaddingEnd="" very late answer but hope it will help someone
Upvotes: 1
Reputation: 1
In addition of Elvis' answer, the app:tabPadding*
attributes could help you to distribute (or normalize the length of) the tab titles.
Upvotes: 0
Reputation: 1530
add app:tabMode="scrollable"
to your <TabLayout.../>
and don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto"
too.
For more info check out https://developer.android.com/reference/android/support/design/widget/TabLayout.html
Upvotes: 32