如何在NestedScrollView内使用RecyclerView ? 设置适配器后,RecyclerView内容不可见。

更新布局代码。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/keyline_1">

    </RelativeLayout>

    <View
        android:id="@+id/separator"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#e5e5e5" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/conversation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

当前回答

保持recyclerview的回收特性并避免recyclerview加载所有数据的一个解决方案是在recyclerview本身设置一个固定的高度。通过这样做,recyclerview只能加载它的高度所能显示给用户的东西,这样当你滚动到底部/顶部时,循环它的元素。

其他回答

我在NestedScrollView内使用RecyclerView,它为我工作。我必须记住的唯一问题是NestedScrollView只接受一个子视图。所以在我的情况下,我使用的LienearLayout视图组,它是住房我的RecyclerView加上其他一些我需要的视图。

我经历了一个问题,把我的RecyclerView内的NestedScrollView。我意识到我的RecyclerView的内容滚动变慢了。

我后来意识到我的RecyclerView正在接收滚动事件,因此与NestedScrollView的滚动行为相冲突。

所以为了解决这个问题,我不得不禁用我的RecyclerView的滚动功能与这个方法movieListNewRecyclerView.setNestedScrollingEnabled(false);

你可以在我的Instagram上查看我实际做了什么。这是我的instagram账号elix03

这就是对我有效的方法

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>

保持recyclerview的回收特性并避免recyclerview加载所有数据的一个解决方案是在recyclerview本身设置一个固定的高度。通过这样做,recyclerview只能加载它的高度所能显示给用户的东西,这样当你滚动到底部/顶部时,循环它的元素。

就我而言,这对我很有效

将android:fillViewport="true"放入NestedScrollView中。 使RecyclerView的高度为wrap_content,即android:layout_height="wrap_content" 将此添加到RecyclerView android:nestedScrollingEnabled="false"

OR

以编程方式,在Kotlin类中

recyclerView。isNestedScrollingEnabled = false

mRecyclerView.setHasFixedSize(假)

RecyclerView与NestedScrollView

    <android.support.v7.widget.RecyclerView
    android:id="@+id/rv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />