How to use tabContentStart to launch content from the middle of the device screen

I use TabLayout and ViewPager

<android.support.v4.view.ViewPager android:id="@+id/view_pager_social_profiles" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager> <android.support.design.widget.TabLayout android:id="@+id/tab_layout_social_profiles" android:layout_width="match_parent" android:layout_height="112dp" app:tabContentStart="72dp" app:tabGravity="center" app:tabIndicatorHeight="0dp" app:tabMode="scrollable"></android.support.design.widget.TabLayout> 

I want to start the contents of the tab from the middle of the screen, so if there is only one tab, it will be aligned exactly in the center of the screen (horizontally), and the selected tab will always be in the center.

+5
source share
3 answers

The fastest and easiest way to get your tabs in the center is to get rid of

 app:tabMode="scrollable" 

in tablayout. This, of course, will keep your tabs in a "fixed" place (not scrollable).

If you really want to have scrollable tabs that start in the center, this GitHub project looks as if it could help you.

+3
source

Use this class. insert this centering tablayout in the java class. use centering tablayout instead of tablayput in your xml design

+1
source

To use content in the center setTabGravity (1) [1 for the center, 0 to fill]

To set up a tab in the center

Application: tabMode = "scroll"

0
source

Source: https://habr.com/ru/post/1265464/


All Articles