安卓工具栏在向上滚动时不能展开

5
我有一个工具栏,当RecyclerView向下滚动时会折叠,但当用户快速向上滚动时,工具栏不会展开。你知道是什么问题吗?
这种行为在这个视频中展示:https://youtu.be/67ntPkW-5XA 布局代码:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="16dp"
    android:clickable="true"
    android:onClick="showText"
    android:src="@drawable/ic_done_white_24dp"
    app:borderWidth="0dp" />

1个回答

2
如果你希望每次向上滚动时都将其展开,你应该在要显示的视图中添加app:layout_scrollFlags="scroll|enterAlways"
据我所知,你想将此添加到你的CollapsingToolbarLayout中。
可能的标志: scroll:对于所有想要滚动到屏幕外的视图都应设置此标志——对于不使用此标志的视图,它们将保持固定在屏幕顶部。 enterAlways:此标志确保任何向下滚动都会导致该视图变为可见,从而启用“快速返回”模式。 enterAlwaysCollapsed:当你的视图声明了最小高度并使用此标志时,你的视图将仅以其最小高度(即“折叠”状态)进入,只有当滚动视图到达顶部时,它才会重新展开到其完整高度。 exitUntilCollapsed:此标志使视图在退出之前滚动到“折叠”状态(其最小高度)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接