16

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>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Naman
  • 161
  • 1
  • 1
  • 4

5 Answers5

33

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

Elvis Chweya
  • 1,532
  • 11
  • 19
  • 3
    This should be correct answer. Also can be done by code, `tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE)` – Anthonyeef Jan 06 '17 at 04:05
7

Just set the TabLayout width to wrap_content. Done.

kopikaokao
  • 500
  • 7
  • 13
1

Try app:tabPaddingEnd="" very late answer but hope it will help someone

Mohammed Rousul
  • 199
  • 3
  • 7
1

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>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Kenny
  • 31
  • 4
0

In addition of Elvis' answer, the app:tabPadding* attributes could help you to distribute (or normalize the length of) the tab titles.

Carlos
  • 1
  • 1