i trying use new design tablayout in project. want layout adapt every screen size , orientation, can seen correctly in 1 orientation.
i dealing gravity , mode setting tablayout as:
tablayout.settabgravity(tablayout.gravity_center); tablayout.settabmode(tablayout.mode_scrollable);
so expect if there no room, tablayout scrollable, if there room, centered.
from guides:
public static final int gravity_center gravity used lay out tabs in center of tablayout.
public static final int gravity_fill gravity used fill tablayout as possible. option takes effect when used mode_fixed.
public static final int mode_fixed fixed tabs display tabs concurrently , best used content benefits quick pivots between tabs. maximum number of tabs limited view’s width. fixed tabs have equal width, based on widest tab label.
public static final int mode_scrollable scrollable tabs display subset of tabs @ given moment, , can contain longer tab labels , larger number of tabs. best used browsing contexts in touch interfaces when users don’t need directly compare tab labels.
so gravity_fill compatible mode_fixed but, @ doesn't specify gravity_center, expect compatible mode_scrollable, using gravity_center , mode_scrollable
so using scrollable in both orientations, not using gravity_center.
this expect landscape; have this, need set mode_fixed, in portrait is:
why gravity_center not working scrollable if tablayout fits screen? there way set gravity , mode dynamically (and see expecting)?
thank much!
edited: layout of tablayout:
<android.support.design.widget.tablayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:background="@color/orange_pager" android:layout_height="wrap_content" />
tab gravity effects mode_fixed
.
one possible solution set layout_width
wrap_content
, layout_gravity
center_horizontal
:
<android.support.design.widget.tablayout android:id="@+id/sliding_tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" app:tabmode="scrollable" />
if tabs smaller screen width, tablayout
smaller , centered because of gravity. if tabs bigger screen width, tablayout
match screen width , scrolling activate.
Comments
Post a Comment