首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在nestedscrollview中使用分页库时,会加载所有数据

在nestedscrollview中使用分页库时,会加载所有数据
EN

Stack Overflow用户
提问于 2019-02-06 14:26:40
回答 3查看 2.3K关注 0票数 9

我正在使用分页库加载数据并填充我的回收器视图,该视图放置在一个nestedscrollview中。但这就像,分页会自动工作,直到所有数据从API获取。我知道这是因为有了nestedscrollview。但不幸的是,我的布局需要滚动视图,因为我在这个片段中有一个顶部部分,而不是recyclerview。这是我的布局

代码语言:javascript
复制
<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
   >
   <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

   //have a layout here which scrolls with recyclerview

      <Recyclerview />

   </ConstraintLayout>

</NestedScrollView>

当我不使用nestedscrollview时,一切都很好。在problem样本git repo中有一个公开的问题来解决这个问题。

https://github.com/googlesamples/android-architecture-components/issues/215

有谁知道如何实现分页时,回收视图是在滚动视图与分页库从Android jetpack。我知道我们可以实现传统的将侦听器附加到nestedscrollview的分页,但我希望使用架构组件库来实现分页。https://developer.android.com/topic/libraries/architecture/paging/

EN

回答 3

Stack Overflow用户

发布于 2020-05-26 17:27:52

使用下面的代码可以解决这个问题。以下是视图层次结构:

代码语言:javascript
复制
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar_layout"
        android:background="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <!-- Put here elements that you need above the recycler view -->

            </LinearLayout>

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>
    <!-- RecyclerView -->
    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nestedScrollingEnabled="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:scrollbars="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

注意:请确保您已经为CoordinatorLayout和AppBarLayout提供了id,以便它将在后端堆栈上保持滚动位置。

票数 8
EN

Stack Overflow用户

发布于 2019-02-13 14:17:20

问题出在嵌套的scrolview中的recyclerview。分页库与此无关。如果您尝试在recyclerview的scroll listener上加载数据,行为将是相同的。

票数 1
EN

Stack Overflow用户

发布于 2020-01-16 23:33:46

分页库不能很好地与nestedScroolView配合使用。因此,您必须使用android:nestedScrollingEnabled="true"将NesteScrollView更改为ScroolView,如下所示:

代码语言:javascript
复制
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:nestedScrollingEnabled="true"
   >
   <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

   //have a layout here which scrolls with recyclerview

      <Recyclerview />

   </ConstraintLayout>

</ScrollView>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54547780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档