问题
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>
回答1:
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
回答2:
Just set the TabLayout width to wrap_content. Done.
回答3:
In addition of Elvis' answer, the app:tabPadding*
attributes could help you to distribute (or normalize the length of) the tab titles.
来源:https://stackoverflow.com/questions/39142613/how-to-make-tab-title-alignment-to-left-in-tablayout-in-android