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.
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.
Use this class. paste this centering tablayout in you java class. use centering tablayout instead of tablayput in your xml design
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With