【问题标题】:how to avoid hiding the tabs when scrolled down?向下滚动时如何避免隐藏选项卡?
【发布时间】:2015-11-18 10:52:52
【问题描述】:

我已经用 TabLayout 实现了 viewpager。每个选项卡都是一个片段。我认为 Tabs 的默认行为是当用户向下滚动时它们被隐藏并在向上滚动时获得可见性。

我也不会有太多的内容来使用标签空间。所以我想始终显示标签。
当用户向下滚动时,如何避免隐藏选项卡?

这是我的带有 ViewPager 的 TabLayout:

<android.support.design.widget.AppBarLayout
    android:id="@+id/myAppBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.TabLayout
        android:id="@+id/myTabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/toolbar_height"
        android:background="@color/white"
        android:overScrollMode="never"
        app:layout_scrollFlags="scroll|enterAlways"
        app:tabIndicatorColor="@color/white"
        app:tabIndicatorHeight="3dp"
        app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/myViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Play 商店中的应用页面始终显示标签。

【问题讨论】:

    标签: android scroll android-viewpager android-tablayout


    【解决方案1】:

    去掉这条线

    app:layout_scrollFlags="scroll|enterAlways"
    

    此标志强制视图(您的 TabLayout)在任何向下的滚动事件上滚动。

    <android.support.design.widget.TabLayout
            android:id="@+id/myTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/toolbar_height"
            android:background="@color/white"
            android:overScrollMode="never"
            app:tabIndicatorColor="@color/white"
            app:tabIndicatorHeight="3dp"
            app:tabMode="scrollable" />
    

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2023-01-19
      • 2016-05-12
      • 2015-11-17
      • 1970-01-01
      相关资源
      最近更新 更多