【发布时间】:2022-03-31 17:45:25
【问题描述】:
我在 nestedscrollview 中使用 recyclerview 滚动整个页面大小,但这破坏了分页功能,因为它会自动加载所有页面而无需用户滚动。
这是我的 xml 布局
<?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"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View android:id="@+id/header_view"
android:layout_width="0dp"
android:layout_height="300dp"
android:layout_marginTop="21dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/picked_up_rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:paddingBottom="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
我正在使用 Paging 3 进行分页
implementation "androidx.paging:paging-runtime-ktx:3.1.0"
【问题讨论】:
-
我不认为你能做到这一点;一旦 recyclerView 处于滚动视图(相同方向)中,您将失去回收视图的能力
标签: android android-recyclerview android-nestedscrollview android-paging-3 nestedrecyclerview