首页 > 解决方案 > NestedScrollView 内的 Androidx Recyclerview

问题描述

我有一个RecyclerViewinside aNestedScrollView但它不可滚动。如果我只是拥有RecyclerView它本身它工作正常,所以我想知道是否有一些我忘记设置的缺失属性。

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            android:overScrollMode="always"
            android:id="@+id/mRecyclerView"/>

</androidx.core.widget.NestedScrollView>

我也尝试将 xml 属性设置android:nestedScrollingEnabled为 true,但没有奏效。

标签: android

解决方案


你需要设置 recyclerView.setNestedScrollingEnabled(false); 在代码中或 android:nestedScrollingEnabled="false" 在您的 xml


推荐阅读