滚动下来时如何避免隐藏标签?

时间:2015-11-18 10:52:53

标签: android scroll android-viewpager android-tablayout

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

我也没有太多内容可以使用标签空间。所以我想总是显示标签 当用户向下滚动时,如何避免隐藏选项卡?

这是我的ViewLager的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商店中的应用页面始终显示标签。

1 个答案:

答案 0 :(得分:3)

取消这一行

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" />