需求描述:在某页面中,顶部是一个ViewPager(图片浏览器),中间是Recyclerview,图片内容浏览,不需要分页功能,尾部是一个Recyclerview,评论列表或者推荐列表,需要分页显示。
    PS:Recyclerview复用机制不可缺失
    像以上这种情况,一般是写一个Recyclerview,添加头部ViewPager,添加尾部评论列表,这确实是一种解决方式,其优缺点可自行体会
    这里推荐另一种可解决的方式:https://github.com/donkingliang/ConsecutiveScroller/tree/master
    这个库有androidx的版本,整个库只有几个类,最主要就是一个自定义的layout,完全可以当做一个LinearLayout去使用,所有滑动事件都可以交给layout去处理;示例代码:

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. android:id="@+id/scrollerLayout"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent"
    7. android:scrollbars="vertical">
    8. <android.support.v4.view.ViewPager
    9. android:layout_width="match_parent"
    10. android:layout_height="200dp"/>
    11. <WebView
    12. android:id="@+id/webView"
    13. android:layout_width="match_parent"
    14. android:layout_height="match_parent" />
    15. <!-- 吸顶-->
    16. <TextView
    17. android:layout_width="wrap_content"
    18. android:layout_height="wrap_content"
    19. android:text="图片列表"
    20. app:layout_isSticky="true"
    21. android:padding="10dp"
    22. />
    23. <android.support.v7.widget.RecyclerView
    24. android:layout_width="match_parent"
    25. android:layout_height="wrap_content"/>
    26. <!-- 吸顶-->
    27. <TextView
    28. android:layout_width="wrap_content"
    29. android:layout_height="wrap_content"
    30. android:text="图片列表"
    31. app:layout_isSticky="true"
    32. android:padding="10dp"
    33. />
    34. <android.support.v7.widget.RecyclerView
    35. android:layout_width="match_parent"
    36. android:layout_height="wrap_content"/>
    37. </com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>

    补充:
    1.还可以实现吸顶效果哦
    2.如果其中某个滑动控件想自行滑动,可以添加代码:app:layout_isConsecutive=”false”
    3.Recyclerview的复用机制还会存在
    4.具体使用步骤可以自行看github