Android NestedScrollView包裹RecyclerView高度撑满所有item,kotlin

Android NestedScrollView包裹RecyclerView高度撑满所有item,kotlin

当用NestedScrollView包裹RecyclerView后,

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" />

</androidx.core.widget.NestedScrollView>

然而设置:

recyclerView?.isNestedScrollingEnabled = false

会使得RecyclerView加载完成所有itemCount的数理,撑满整个RecyclerView高度,这深深改变了RecyclerView只加载显示当前屏幕可见区域的特性,此时RecyclerView一次性加载全部item。

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/131669489