azhar azhar - 3 months ago 14
Android Question

How to fit the tab width screen in android

I implement the tab layout using android support library and it looks like

enter image description here

Here the tab width is not fit with screen and my layout is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"

android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />

</LinearLayout>

Answer

Try calling those methods on your TabLayout:

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