Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single tab in TabLayout is not covering the entire width

I have created a view pager with TabLayout. Now the issue is if I have 2 or more tabs then everything is fine. But if I am having only one tab then it is not covering the entire screen width. PFA the xml layout

 <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed"
        style="@style/TabLayout"
        android:fillViewport="true"
        android:layout_below="@id/ssrToolbar"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sliding_tabs"
        android:layout_above="@+id/llButtonLayout"
        android:background="@android:color/white" />

Also here are the two images

single tab

two tabs

like image 505
mohan mishra Avatar asked Nov 23 '15 15:11

mohan mishra


People also ask

Can we use TabLayout without ViewPager in Android?

It is possible to use a TabLayout without a ViewPager by using a TabLayout. OnTabSelectedListener . For navigation within an Activity , manually populate the UI based on the tab selected.


1 Answers

If someones still interested you should add this property for TabLayout in xml app:tabMaxWidth="big_number", for big_number i chose 2000dp. If you are not assigning any value default implementation subtracts widths measured specifications size with TAB_MIN_WIDTH_MARGIN value.

like image 115
Tiko Avatar answered Oct 13 '22 06:10

Tiko