如何在以编程方式滚动时禁用 tabLayout 滚动动画?

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

当活动启动时,我以编程方式更改选项卡布局的位置,但在以参数方式更改选项卡布局位置时,它会提供从第 0 个选项卡到我要切换到的选项卡的滚动动画

我使用的代码是

new Handler().postDelayed(() -> Objects.requireNonNull
(binding.tabLayout.getTabAt(5)).select(), 100);

我也尝试过

binding.tabLayout.setSmoothScrollingEnabled(false);

但每次它都会给出我不想要的滚动动画。有可能实现这一目标吗?

android android-layout kotlin android-tablayout
2个回答
0
投票

您指的是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" />

但是如果你指的是由于viewpager而发生的选项卡内容,那么当点击选项卡时你需要使用viewpager的这种方法:

mViewPager.setCurrentItem(position, false)

第二个参数是 smoothScroll 如果为 false,则禁用滚动动画


0
投票

您可以使用 binding.viewPagerHome.isUserInputEnabled = false

© www.soinside.com 2019 - 2024. All rights reserved.