当recyclerview位于嵌套滚动视图中时,即使没有用户交互,Paging3也会继续加载数据



我一直试图让回收器视图使用滚动视图而不是嵌套滚动视图,但我的用例是,我需要让回收器的视图滚动到使用嵌套滚动视图轻松实现的完整布局,但它一直在调用API,因为嵌套滚动视图需要知道它需要容纳多少孩子。如果有任何其他解决方法或任何东西可以使用滚动或嵌套滚动视图进行分页

这是我的XML。

<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="viewModel"
type="comapp.viewmodels.HomeViewModel" />
</data>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_home"
app:count="@{viewModel.cartCount}" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:indicatorColor="@color/app_global_green"
android:indeterminate="true" />
<androidx.core.widget.NestedScrollView
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="wrap_content">

<androidx.cardview.widget.CardView
android:id="@+id/searchcard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:elevation="15dp"
android:visibility="gone"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_search_view"
android:elevation="15dp"
android:queryHint="Search by Product ID or name" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/start_your_business"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:lines="2"
android:padding="8dp"
android:text="Apna karobar shuru karein n asaani say"
android:textAlignment="center"
android:textAppearance="@style/start_your_"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchcard" />
<androidx.cardview.widget.CardView
android:id="@+id/btn_watch_video"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@id/start_your_business"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:backgroundTint="@color/green_dark"
app:cardCornerRadius="8dp"
app:cardElevation="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/start_your_business">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="8dp"
android:gravity="center"
android:text="@string/watch_video"
android:textColor="@color/white" />
</androidx.cardview.widget.CardView>

<ImageView
android:id="@+id/bg_home_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_watch_video"
android:layout_marginTop="8dp"
android:src="@drawable/ic_backhome"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_watch_video" />
<!--
<TextView
android:id="@+id/top_categories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/top_categories"
android:textAppearance="@style/home_headings"
android:padding="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/bg_home_image" />-->
<!--
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/category_home_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_categories"
app:listTopCategories="@{viewModel.topCategories}"
app:spanCount="2"
tools:itemCount="16"
tools:listitem="@layout/category_grid_view_home"/>
<ImageView
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:markazApiStatus="@{viewModel.status}" />-->

<ImageView
android:id="@+id/home_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_watch_video"
android:src="@drawable/home_image"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/bg_home_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/bg_home_image"
app:layout_constraintVertical_bias="1.0" />

<androidx.cardview.widget.CardView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_catalogs">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/filterSpinner"
android:layout_width="@dimen/_270sdp"
android:layout_height="32dp"
android:layout_margin="4dp"
android:entries="@array/filterTypes"
android:spinnerMode="dropdown" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/top_catalogs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/bg_home_image"
android:layout_marginTop="8dp"
android:padding="8dp"
android:text="@string/top_catalogs"
android:textAppearance="@style/home_headings"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="@+id/home_image"
app:layout_constraintHorizontal_bias="0.068"
app:layout_constraintStart_toStartOf="@+id/home_image"
app:layout_constraintTop_toBottomOf="@+id/bg_home_image" />
<!--      <com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer"
android:forceHasOverlappingRendering="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sort"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
<include layout="@layout/shimmer_catalog" />
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/catalog_home_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_catalogs"
android:layout_marginTop="8dp"
android:clipToPadding="true"
android:orientation="vertical"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sort"
app:spanCount="1"
tools:itemCount="8"
tools:listitem="@layout/viewholder_catalog" />
<ImageView
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/top_catalogs"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/catalog_home_list" />
<androidx.cardview.widget.CardView
android:id="@+id/cvResellerInfo"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="44dp"
android:layout_marginTop="132dp"
android:layout_marginEnd="44dp"
android:visibility="invisible"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_image">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_share_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/share_product_and_place_order"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</layout>

这可能有点复杂,recyclerView自己管理显示和操作的ho数据。如果它解决了你的问题,请从这里查看答案。在这里输入链接描述

相关内容

  • 没有找到相关文章