简体   繁体   中英

How to space tab layout text

I am building an android app with tabs but the result I am getting is not what I wish for. I will like to implement something similar to what whatsapp has.

Below is what I want to do:

My Tab

我的应用截图

Whatsapp

whatsapp截图

This can be achieved like below

By xml

<android.support.design.widget.TabLayout
    android:id="@+id/tab"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:tabIndicatorColor="@android:color/white"
    app:tabIndicatorHeight="4dp"
    app:tabMaxWidth="0dp"
    app:tabMode="fixed" />

And programatically

tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

Write this line inside Tablayout app:tabGravity="fill"

for example:

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM