我正在使用分页库加载数据并填充我的回收器视图,该视图放置在一个nestedscrollview中。但这就像,分页会自动工作,直到所有数据从API获取。我知道这是因为有了nestedscrollview。但不幸的是,我的布局需要滚动视图,因为我在这个片段中有一个顶部部分,而不是recyclerview。这是我的布局
<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/
发布于 2020-05-26 17:27:52
使用下面的代码可以解决这个问题。以下是视图层次结构:
<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,以便它将在后端堆栈上保持滚动位置。
发布于 2019-02-13 14:17:20
问题出在嵌套的scrolview中的recyclerview。分页库与此无关。如果您尝试在recyclerview的scroll listener上加载数据,行为将是相同的。
发布于 2020-01-16 23:33:46
分页库不能很好地与nestedScroolView配合使用。因此,您必须使用android:nestedScrollingEnabled="true"将NesteScrollView更改为ScroolView,如下所示:
<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>https://stackoverflow.com/questions/54547780
复制相似问题