androidandroid-tablayoutandroid-tabs

TabLayout first item offset on the left


I have a TabLayout with horizontally scrollable tabs using Material Design guidelines state.

On mobile and desktop, offset the first tab on the left to sign that tabs are scrollable.

enter image description here

How can I achieve this? If I add a left margin or padding this will only move in all tabs to the right side but I can't scroll the tabs all the way to the left side of the screen anymore.

I also tried this:

tabLayout.setScrollPosition(2, 0.2f, true);

Which would pre-select the 3rd item and offsets the sliding indicator by 0.2 which in the end looks weird and also doesn't actually move the first tab item to the right side on the screen.

Thanks for help in advance!


Solution

  • I found the solution. In the layout XML you can set the content offset with "tabContentStart".

    Example:

    <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabContentStart="57dp"
            app:tabMode="scrollable" />