Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the best way to set the tab layout tabmode for tablets?

I am using the TabLayout from Android Design support library. How can I use MODE_SCROLLABLE along with GRAVITY_FILL so that it looks the same across all devices and orientations?

Currently if I use MODE_SCROLLABLE, it looks good on 7" tablet, but on 10" tablet, the tabs are aligned to the left. I want to be able to use GRAVITY_FILL for all sizes.

This is my tablayout:

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="72dp"            
/>

and I am setting the mode in code

 tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
like image 488
Sammys Avatar asked Jul 08 '15 21:07

Sammys


People also ask

How do I change the width of my Android tablet?

Click the Default box for the Tab Scrolling setting. Now select one of the tabs shrink to options: pinned, medium, or large width setting. Alternatively, you can select a tabs don't shrink or Disabled option on that drop-down menu. Press Relaunch after selecting a tab width setting.

Which layout is used to implement horizontal tabs?

A TabLayout provides a way to display tabs horizontally.


1 Answers

Per the TabLayout.GRAVITY_FILL documentation:

Gravity used to fill the TabLayout as much as possible. This option only takes effect when used with MODE_FIXED.

Therefore by setting your mode to MODE_SCROLLABLE, tabs are always aligned from the starting edge - the only difference between tablets and phones for MODE_SCROLLABLE is the minimum width of tabs, as set by the tabs material design spec.

Note that you can specify both gravity and tab mode via XML if you want to set the view to always be scrollable:

<android.support.design.widget.TabLayout
  android:id="@+id/tab_layout"
  android:layout_width="match_parent"
  android:layout_height="72dp"
  app:tabMode="scrollable"
/>
like image 107
ianhanniballake Avatar answered Sep 29 '22 14:09

ianhanniballake