【问题标题】:Scroll Views above RecyclerViewRecyclerView 上方的滚动视图
【发布时间】:2019-06-01 16:05:48
【问题描述】:

我的 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 上隐藏显示切换布局。
  • 您需要 Gmail 的 Android 应用搜索栏等功能。我说的对吗?
  • 我希望它与recyclerview一起滚动,而不是隐藏它!就像新设计的 Gmail 应用一样,搜索栏会随着 recyclerview 滚动...

标签: android kotlin android-recyclerview android-coordinatorlayout


【解决方案1】:

首先,确定您的 recylerview 是向上滚动还是向下滚动。以及根据该滚动隐藏/显示和动画切换布局。

例如

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

这是我确定 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
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    相关资源
    最近更新 更多