Как шаг за шагом прокрутить экран с помощью RecyclerView внутри и загрузить элементы RecyclerView? - PullRequest
0 голосов
/ 24 февраля 2020

У меня есть страница галереи в моем проекте. На этой странице есть разные типы представлений, такие как RecyclerView - TextView - ImageView. Если я устанавливаю высоту «wrap_content» RecyclerView, мой RecyclerView загружает все элементы. Это на мой взгляд, потому что в некоторых галереях слишком много предметов. Я хочу загружать элементы шаг за шагом. Но если я установлю высоту «match_constraint» для RecyclerView, у моей страницы галереи будет 2 прокрутки (одна из них - ScrollView, одна из них - RecyclerView). Так что все взгляды не могли прокручиваться вместе. Как шаг за шагом прокручивать экран с помощью RecyclerView внутри с помощью 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: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>

1 Ответ

0 голосов
/ 24 февраля 2020

Использовать библиотеку пагинации от Android Jetpack. Проверьте из официальной документации здесь .

Вы также можете найти хороший учебник Здесь

...