【问题标题】:How to disable tabLayout scroll animation while scrolling it programetically?如何在以编程方式滚动时禁用 tabLayout 滚动动画?
【发布时间】:2020-04-01 21:01:47
【问题描述】:

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

我使用的代码是

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

我也试过了

binding.tabLayout.setSmoothScrollingEnabled(false);

每次它都会给出我不想要的滚动动画。有没有可能做到这一点?

【问题讨论】:

    标签: android android-layout kotlin android-tablayout


    【解决方案1】:

    你指的是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而发生的tab的内容,那么在点击tab的时候你需要使用viewpager的这个方法:

    mViewPager.setCurrentItem(position, false)
    

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

    【讨论】:

    • app:tabIndicatorHeight="0dp" 这将删除高度,但我也需要它,但不想用动画滚动标签布局
    • 您可以将指标的颜色属性更改为与背景相同。例如:app:tabIndicatorColor="#9cc8df"
    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多