簡體   English   中英

如何使用 RecyclerView 逐步加載帶有 RecyclerView 的屏幕滾動屏幕?

[英]How do I scroll the screen with the RecyclerView inside with RecyclerView load items step by step?

我的項目中有畫廊頁面。 此頁面中有不同的視圖類型,例如 RecyclerView - TextView - ImageView。 如果我設置 RecyclerView 的高度“wrap_content”,我的 RecyclerView 會加載所有項目。 我的看法是凍結,因為有些畫廊有太多的項目。 我想逐步加載項目。 但是如果我設置 RecyclerView 的高度“match_constraint”,我的畫廊頁面有 2 個滾動(其中一個是 ScrollView,其中一個是 RecyclerView)。 所以所有的視圖都不能一起滾動。 如何使用 RecyclerView 逐步加載帶有 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:id="@+id/detail_fragment_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:fillViewport="true"
        android:fitsSystemWindows="false"
        android:focusable="true"
        tools:context=".DetailActivity">



 <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/detail_fragment_constraint"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:focusable="true"
            android:scrollbars="none">

<TextView
        android:id="@+id/feed_detail_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="12dp"
        android:paddingLeft="8dp"
        android:paddingTop="2dp"
        android:paddingRight="8dp"
        android:paddingBottom="2dp"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent” />

<TextView
        android:id="@+id/feed_detail_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        app:layout_constraintBottom_toBottomOf="@+id/feed_detail_category"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/feed_detail_category" />

<TextView
        android:id="@+id/feed_detail_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:paddingLeft="8dp"
        android:paddingTop="8dp"
        android:paddingRight="8dp"
        android:paddingBottom="8dp"
        android:textColor="@android:color/black"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/feed_detail_category" />

    
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/comment_recycler_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:visibility="visible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/feed_detail_title” />         


 </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.core.widget.NestedScrollView>

使用 Android Jetpack 中的分頁庫。 這里的官方文檔中查看

你也可以在這里找到一個很好的教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM