如何在以编程方式滚动时禁用 tabLayout 滚动动画?
How to disable tabLayout scroll animation while scrolling it programetically?
我在 activity 启动时以编程方式更改选项卡布局的位置,但在参数化更改选项卡布局位置时,它会提供从第 0 个选项卡到我要切换到的选项卡的滚动动画
我使用的代码是
new Handler().postDelayed(() -> Objects.requireNonNull
(binding.tabLayout.getTabAt(5)).select(), 100);
我也试过
binding.tabLayout.setSmoothScrollingEnabled(false);
仍然每次它都会提供我不想要的滚动动画。有没有可能实现这个目标?
你指的是TabLayout的下划线滚动动画吗?
你可以设置
app:tabIndicatorHeight="0dp"
举个例子:
<android.support.design.widget.TabLayout
android:id="@+id/comtabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:tabIndicatorHeight="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@android:color/white" />
但是如果你引用tab的内容是因为viewpager导致的,那么点击tab的时候就需要用到viewpager的这个方法:
mViewPager.setCurrentItem(position, false)
第二个参数为 smoothScroll,如果为 false,则禁用滚动动画
我在 activity 启动时以编程方式更改选项卡布局的位置,但在参数化更改选项卡布局位置时,它会提供从第 0 个选项卡到我要切换到的选项卡的滚动动画
我使用的代码是
new Handler().postDelayed(() -> Objects.requireNonNull
(binding.tabLayout.getTabAt(5)).select(), 100);
我也试过
binding.tabLayout.setSmoothScrollingEnabled(false);
仍然每次它都会提供我不想要的滚动动画。有没有可能实现这个目标?
你指的是TabLayout的下划线滚动动画吗? 你可以设置
app:tabIndicatorHeight="0dp"
举个例子:
<android.support.design.widget.TabLayout
android:id="@+id/comtabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:tabIndicatorHeight="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@android:color/white" />
但是如果你引用tab的内容是因为viewpager导致的,那么点击tab的时候就需要用到viewpager的这个方法:
mViewPager.setCurrentItem(position, false)
第二个参数为 smoothScroll,如果为 false,则禁用滚动动画