Man Cuzzy
Man Cuzzy

Reputation: 23

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

my app's screenshot

Whatsapp

whatsapp screenshot

Upvotes: 2

Views: 531

Answers (2)

Emmanuel Ayela
Emmanuel Ayela

Reputation: 192

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);

Upvotes: 1

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" />

Upvotes: 0

Related Questions