在 RecyclerView 上方滚动视图

Scroll Views above RecyclerView

我的 RecyclerView 上方有一些视图,我想让它们都可滚动,如下所示:

当我滚动时,切换按钮应该如下所示滚动:

我的布局如下:

<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <ToggleButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textOn="Active"
                android:textOff="Completed"/>

        <fragment
                android:id="@id/Container_fromHomeActivity_BottomAppBarFragments"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:defaultNavHost="@bool/Navigation_NavigationHost_Default"
                app:navGraph="@navigation/bottomappbar_navigation"
                tools:layout="@layout/fragment_to_do"/>

    </LinearLayout>

    <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@id/BottomAppBar_fromHomeActivity_Main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:fabAlignmentMode="center"
            app:navigationIcon="@drawable/ic_menu_dark"
            app:menu="@menu/menu_bottomappbar_main"/>


    <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@id/FAB_fromHomeActivity_BottomAppBarAttached"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_add_dark"
            android:backgroundTint="@color/colorAccent"
            app:layout_anchor="@id/BottomAppBar_fromHomeActivity_Main"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

但是当我尝试滚动时,切换按钮固定在屏幕上。只有 recyclerview 在切换按钮后面滚动。

有人能帮忙吗?

首先,确定您的 recylerview 是向上滚动还是向下滚动。和 Hide/show 并根据滚动设置动画切换布局。

例如

  • 动画向上滚动和
  • 向下滚动动画。

这是我的代码,用于确定向上和向下的 recylerviews

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        if (dy > 0 && toggelLayout.getVisibility() == View.VISIBLE) {
            //Hide
        } else if (dy < 0 && toggelLayout.getVisibility() !=View.VISIBLE) {
           //Show
        }
    }
});