滚动期间仅隐藏应用栏中的底部视图



我想实现布局,类似于以下存根:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.appbar.AppBarLayout>
        <View android:id="@+id/firstView"/>
        <View android:id="@+id/secondView"/>
    </com.google.android.material.appbar.AppBarLayout>
    <androidx.recyclerview.widget.RecyclerView />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

我想实现以下行为:当回收器视图向上滚动时,只有secondView折叠。无论我尝试什么,我都设法只隐藏了滚动上的firstView或两者兼而有之。我怎么能只隐藏第二个?

将第二个视图移出 AppBarLayout。使用线性布局包装第二个视图和回收器视图,并添加滚动行为。但缺点是第二个视图无法滚动。