Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use tabContentStart to start content from middle of device screen

I am using 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 tab content from the middle of screen so if there is only one tab it will be aligned exactly center of screen (horizontally) and also selected tab will be always in center.

like image 731
virengujariya Avatar asked Mar 15 '17 00:03

virengujariya


Video Answer


2 Answers

The quickest and easiest way to get your tabs in the center would be to get rid of

app:tabMode="scrollable"

in your TabLayout. This would, of course, keep your tabs in a "fixed" location (not scrollable).

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

like image 174
Rapunzel Van Winkle Avatar answered Sep 27 '22 22:09

Rapunzel Van Winkle


Use this class. paste this centering tablayout in you java class. use centering tablayout instead of tablayput in your xml design

like image 32
SANAT Avatar answered Sep 27 '22 22:09

SANAT