1

The height of my tablayout is wrap content. But it's not working. I am pasting the screenshot here. It's working OK in mobile phones but not in tab.

enter image description here

This problem was also with width but the tag app:tabMaxWidth="0dp" helped me out. How can i overcome this? here is the code to layout.

<android.support.design.widget.TabLayout
    android:id="@+id/tablayout_add"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMaxWidth="0dp"
    android:minHeight="0dp"
    android:layout_gravity="bottom"
    android:layout_below="@+id/relativeLayout"
    app:tabGravity="fill"
    app:tabBackground="@drawable/tab_color_selector"
    app:tabIndicatorColor="@color/sea_green"
    app:tabIndicatorHeight="2dp"
    app:tabMode="fixed"
    android:clickable="false"
/>
Kylo Ren
  • 486
  • 6
  • 24
  • Thank you @halfer but i followed the answer from this link and it worked perfecty. https://stackoverflow.com/questions/30843775/tab-not-taking-full-width-on-tablet-device-using-android-support-design-widget – Kylo Ren Feb 22 '18 at 10:25
  • 1
    Just corrected it. – Kylo Ren Feb 22 '18 at 10:28

2 Answers2

0

As per material design guideline tab layout height is 48dp. Enter this value in dimen file and use that dimension key in height.

And tab layout tab text size is 14sp.

Jaymin Soni
  • 116
  • 5
  • wrapcontet will not work? will it not wrap the content according to the width? – Kylo Ren Nov 28 '17 at 14:20
  • please elaborate your answer. How will i use this value in the xml? if i use the value in tabl widht will it not affect the layout for other devices such as mobiles? – Kylo Ren Nov 28 '17 at 14:21
0

The problem was with the parent of the tablayout. The tablayout was ok. Here is the code for parent item.

    <RelativeLayout
        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:background="@color/default_app_white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >
        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout_add"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            android:minHeight="0dp"
            android:layout_gravity="bottom"
            android:layout_below="@+id/relativeLayout"
            app:tabGravity="fill"
            app:tabBackground="@drawable/tab_color_selector"
            app:tabIndicatorColor="@color/sea_green"
            app:tabIndicatorHeight="2dp"
            app:tabMode="fixed"
            android:clickable="false"/>
</RelativeLayout> 
Kylo Ren
  • 486
  • 6
  • 24