Android 当滚动视图到达顶部时,停止折叠AppBarLayout中的ToolbarLayout展开

Android 当滚动视图到达顶部时,停止折叠AppBarLayout中的ToolbarLayout展开,android,android-collapsingtoolbarlayout,android-appbarlayout,Android,Android Collapsingtoolbarlayout,Android Appbarlayout,我希望达到相同的appbarlayout行为。从下面的gif可以看到 当列表到达顶部时,它不会触发appbarlayout展开。它将在第二次向上滚动时展开 有人知道实现这一目标的方法吗 我通过做以下事情来模仿这种行为: 考虑一下这个布局 <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.

我希望达到相同的appbarlayout行为。从下面的gif可以看到

当列表到达顶部时,它不会触发appbarlayout展开。它将在第二次向上滚动时展开

有人知道实现这一目标的方法吗


我通过做以下事情来模仿这种行为:

考虑一下这个布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:layout_scrollFlags="snap|scroll|exitUntilCollapsed">

            <androidx.appcompat.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> 
这样就行了。 我相信有更好的方法来实现这一点,但这就是我解决问题的方法

list.setOnScrollChangeListener { list, _, _, _, _ ->
    list.isNestedScrollingEnabled = !list.canScrollVertically(-1)
}