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

和自甴很熟 提交于 2019-12-10 03:31:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!