向上滚动时,Android工具栏不会展开

Ale*_*rat 5 android material-design android-design-library

我有一个工具栏,当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" />
Run Code Online (Sandbox Code Playgroud)

Gen*_*kin 2

如果您希望它在每次向上滚动时展开,您应该添加app:layout_scrollFlags="scroll|enterAlways"到您想要显示的视图。

\n\n

据我了解,您想将其添加到您的CollapsingToolbarLayout.

\n\n

可能的标志:

\n\n

scroll:应该为所有想要滚动离开屏幕的视图设置此标志 - 对于不使用此标志的视图,它们\xe2\x80\x99将保持固定在屏幕顶部

\n\n

enterAlways:此标志确保任何向下滚动都会导致此视图变得可见,从而启用 \xe2\x80\x98 快速返回\xe2\x80\x99 模式

\n\n

enterAlwaysCollapsed:当您的视图声明了 minHeight 并且您使用此标志时,您的视图将仅以最小高度进入(即 \xe2\x80\x98collapsed\xe2\x80\x99),只有当滚动视图已到达 \xe2\x80\x99 顶部。

\n\n

exitUntilCollapsed:此标志导致视图在退出之前滚动直到 \xe2\x80\x98collapsed\xe2\x80\x99 (其 minHeight)

\n