Pra*_*hil 9 android android-layout android-architecture-components android-jetpack
我正在使用分页库来加载数据并填充我放置在nestedscrollview 中的recyclerview。但这就像,分页会自动工作,直到从 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>
Run Code Online (Sandbox Code Playgroud)
当我不使用nestedscrollview 时,一切正常。googlesamples git repo regsrding 中有一个未解决的问题。
https://github.com/googlesamples/android-architecture-components/issues/215
有谁知道当回收视图位于带有 Android jetpack 分页库的滚动视图中时,我们如何实现分页。我知道我们可以实现传统类型的分页,将侦听器附加到nestedscrollview,但我希望使用架构组件库实现分页。 https://developer.android.com/topic/libraries/architecture/paging/
使用下面的代码将解决问题。这是视图层次结构:
<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>
Run Code Online (Sandbox Code Playgroud)
注意:请确保您已将 id 赋予 CoordinatorLayout 和 AppBarLayout,以便它在返回堆栈上保留滚动位置。
| 归档时间: |
|
| 查看次数: |
2033 次 |
| 最近记录: |