how to avoid hiding the tabs when scrolled down?

亡梦爱人 提交于 2020-01-25 03:39:09

问题


I have implemented viewpager with TabLayout. Each tab is a Fragment. I think the default behavior of Tabs is that they are hidden when user scrolls down and gets visibility when scrolled up.

I wont have much content to make use of the tabs space too. So I want to show the tabs always.
How can I avoid hiding the Tabs when user scrolls down ?

Here is my TabLayout with ViewPager:

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

Apps page in Play store always shows the tabs.


回答1:


Take off this line

app:layout_scrollFlags="scroll|enterAlways"

this flag forces the view (your TabLayout) to scroll on any downwards scroll event.

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


来源:https://stackoverflow.com/questions/33778101/how-to-avoid-hiding-the-tabs-when-scrolled-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!