how to use tabContentStart to start content from middle of device screen
Asked Answered
D

3

6

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.

Defoliant answered 15/3, 2017 at 0:55 Comment(0)
M
2

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.

Minuteman answered 22/3, 2017 at 6:25 Comment(0)
T
1

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

Teddie answered 22/3, 2017 at 7:22 Comment(0)
V
0

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

To set your tab in center

app:tabMode="scrollable"

Ventriloquize answered 28/3, 2017 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.