需求描述:在某页面中,顶部是一个ViewPager(图片浏览器),中间是Recyclerview,图片内容浏览,不需要分页功能,尾部是一个Recyclerview,评论列表或者推荐列表,需要分页显示。
PS:Recyclerview复用机制不可缺失
像以上这种情况,一般是写一个Recyclerview,添加头部ViewPager,添加尾部评论列表,这确实是一种解决方式,其优缺点可自行体会
这里推荐另一种可解决的方式:https://github.com/donkingliang/ConsecutiveScroller/tree/master
这个库有androidx的版本,整个库只有几个类,最主要就是一个自定义的layout,完全可以当做一个LinearLayout去使用,所有滑动事件都可以交给layout去处理;示例代码:
<?xml version="1.0" encoding="utf-8"?><com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/scrollerLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:scrollbars="vertical"><android.support.v4.view.ViewPagerandroid:layout_width="match_parent"android:layout_height="200dp"/><WebViewandroid:id="@+id/webView"android:layout_width="match_parent"android:layout_height="match_parent" /><!-- 吸顶--><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="图片列表"app:layout_isSticky="true"android:padding="10dp"/><android.support.v7.widget.RecyclerViewandroid:layout_width="match_parent"android:layout_height="wrap_content"/><!-- 吸顶--><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="图片列表"app:layout_isSticky="true"android:padding="10dp"/><android.support.v7.widget.RecyclerViewandroid:layout_width="match_parent"android:layout_height="wrap_content"/></com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>
补充:
1.还可以实现吸顶效果哦
2.如果其中某个滑动控件想自行滑动,可以添加代码:app:layout_isConsecutive=”false”
3.Recyclerview的复用机制还会存在
4.具体使用步骤可以自行看github
