Android TabLayout selected item position

Viewed 96

I have a view pager with TabLayout, like this:

<ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"/>

   <ViewPager>

How on Earth can I set the selected item to scroll to the first position?

I.E. if I have 6 tabs, like Tab1, Tab2, Tab3, Tab4, Tab5, Tab6 - every time an item gets selected it should go to the beginning. Like this (* represent selected tab):

*Tab1* Tab2 Tab3 Tab4  (rest invisible)
*Tab2* Tab3 Tab4 Tab5  (rest invisible)
*Tab3* Tab4 Tab5 Tab6  (rest invisible)

By default TabLayout centers the selected tab (except the preselected one).

0 Answers
Related