简体   繁体   中英

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

I have gallery page in my project. There are different view types in this page like RecyclerView - TextView - ImageView. If I set height "wrap_content" of RecyclerView, my RecyclerView loads all items. That's freeze to my view, because of some galleries has too many items. I want to load items step by step. But If I set height "match_constraint" of RecyclerView, my gallery page has 2 scroll (One of them is ScrollView, one of them is RecyclerView). So all view couldn't scroll with together. How do I scroll the screen with the RecyclerView inside with RecyclerView load items step by step?

Actually my XML is too long so I didn't add some views in following code.

<?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>

Use Pagination library from Android Jetpack. Check from official documentation here .

You can also find a good tutorial Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM