TabLayout左侧的第一个项目偏移量

问题描述 投票:0回答:1

我有一个TabLayout,带有可水平滚动的标签,使用Material Design指南状态。

在移动设备和桌面设备上,偏移左侧的第一个选项卡以标记选项卡是否可滚动。

enter image description here

我怎样才能做到这一点?如果我添加左边距或填充,这将仅在所有选项卡中移动到右侧,但我不能将标签一直滚动到屏幕的左侧。

我也试过这个:

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

这将预先选择第3项并将滑动指示器偏移0.2,这最终看起来很奇怪,并且实际上并没有将第一个标签项移动到屏幕右侧。

提前感谢您的帮助!

android android-tablayout android-tabs
1个回答
2
投票

我找到了解决方案。在布局XML中,您可以使用“tabContentStart”设置内容偏移量。

例:

<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" />
© www.soinside.com 2019 - 2024. All rights reserved.