【问题标题】:auto pagination if using recyclerview inside NestedSrollView with Paging 3?如果在带有分页 3 的 NestedSrollView 中使用 recyclerview,自动分页?
【发布时间】: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


【解决方案1】:

在 Paging3 库中,您可以定义一个 LoadStateAdapter 并将其附加到您的 PagingDataAdapter,然后您可以直接附加页脚和页眉视图。

如果您不想使用 LoadStateAdapter,那么您可以为您的 PagingDataAdapter 创建不同的项目,然后使用项目视图类型来检索您想要的内容。使用这种方法,您可以摆脱 NestedScrollView,这是无用的,因为 RecyclerView 实现了 ScrollingView

【讨论】:

    猜你喜欢
    • 2017-02-03
    • 1970-01-01
    • 2016-11-22
    • 2012-05-01
    • 1970-01-01
    • 2021-07-18
    • 2017-03-28
    • 2021-06-04
    • 2016-01-02
    相关资源
    最近更新 更多