【问题标题】:Unable to scroll RecyclerView无法滚动 RecyclerView
【发布时间】:2020-04-16 18:35:37
【问题描述】:

我有问题:RecyclerView 不滚动。 设计:用菜单覆盖 Image 然后 RecyclerView。 它显示 RecyclerView 但我无法触摸到它只是很烂 我已经厌倦了:用 RecyclerView 替换菜单,但这会造成很大的问题 和 setNestedScrollingEnabled 太。 有爱吗?

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!--    background Logo-->
    <ImageView
        android:background="@color/brown"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:src="@drawable/haneenrama"
        android:contentDescription="@string/name_offical"
        android:scaleType="centerCrop"
        ></ImageView>

    <!--    RecyclerView-->
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_marginTop="250dp"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </androidx.recyclerview.widget.RecyclerView>
    </androidx.core.widget.NestedScrollView>

<!--menu-->
    <androidx.drawerlayout.widget.DrawerLayout
        android:layout_width="match_parent"
        tools:openDrawer="end"
        android:layout_height="match_parent"
        android:id="@+id/drawer_layout">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            android:background="@color/blue"
            ></androidx.appcompat.widget.Toolbar>
    </RelativeLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/NavigationView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@color/white"
    app:itemTextColor="@color/black"
    app:itemIconTint="@color/black"
    app:itemBackground="@color/rmade"
    app:menu="@menu/main_menu"
    app:headerLayout="@layout/menu_header"
    android:layout_gravity="start"
    ></com.google.android.material.navigation.NavigationView>
    </androidx.drawerlayout.widget.DrawerLayout>





</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

  • 您真的需要NestedScrollView 吗?这可能是你的问题,至少我有同样的问题......可以删除它吗?
  • 否则,只需在您的 RecyclerView 中尝试此操作:app:layout_behavior="@string/appbar_scrolling_view_behavior"
  • 您能否发布图片以获得您的 UI 的可视化表示?你能告诉我们你是在 Recyclerview 项目上滚动还是在图像上滚动?

标签: android xml android-recyclerview


【解决方案1】:

您可以尝试删除您的 NestedScrollView,因为它与 RecyclerView 重叠,这就是它不滚动的原因。

否则,您可以将该代码插入您的RecyclerCode

 app:layout_behavior="@string/appbar_scrolling_view_behavior"

可以找到更详细的答案here

【讨论】:

  • 我做了但没有结果。
  • @user113428 你到底做了什么?我列出了 2 个选项
  • 这两个,我刚刚去掉了NastedScrollView
  • 你能分享一张它的样子吗?也许你的 RecyclerView 初始化代码@user113428
【解决方案2】:

试试

recyclerView.setNestedScrollingEnabled(false);

【讨论】:

    【解决方案3】:

    我喜欢它。 这是 Cover RecyclerView

        <!--menu-->
    <androidx.drawerlayout.widget.DrawerLayout
        android:layout_width="match_parent"
        tools:openDrawer="end"
        android:layout_height="match_parent"
        android:id="@+id/drawer_layout">
    

    所以我将其替换为:

    <!--menu-->
    <androidx.drawerlayout.widget.DrawerLayout
        android:layout_width="match_parent"
        tools:openDrawer="end"
        android:layout_height="match_parent"
        android:id="@+id/drawer_layout">
    
        <!--    RecyclerView-->
    
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_marginTop="250dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </androidx.recyclerview.widget.RecyclerView>
    

    【讨论】:

      【解决方案4】:

      请在 NestedScrollView 标签中添加android:fillViewport="true"...
      然后在 RecyclerView 标签中添加android:nestedScrollingEnabled="true"...

      <androidx.core.widget.NestedScrollView
              android:layout_width="match_parent"
              android:layout_marginTop="250dp"
              android:layout_height="match_parent"
              android:fillViewport="true">
              <androidx.recyclerview.widget.RecyclerView
                  android:id="@+id/recycler"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:nestedScrollingEnabled="true">
              </androidx.recyclerview.widget.RecyclerView>
          </androidx.core.widget.NestedScrollView>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-30
        • 2020-08-11
        • 2022-01-25
        • 1970-01-01
        相关资源
        最近更新 更多