上滑吸顶+标题页面左右滑动+横滑和竖滑列表+标题页面数据和数量更新
上滑吸顶
CoordinatorLayout
+AppBarLayout
+CollapsingToolbarLayout
左右滑动
ViewPager2
+TabLayout
+Fragment
横滑和竖滑列表
RecycleView
+NestedScrollableHost
标题页面数据和数量
TabLayoutMediator
+声明周期检测+缓存优化
RecycleView和Viewpage2的滑动冲突
/**
- Created by Tanzhenxing
- Date: 2021/4/7 7:04 下午
- Description:解决 [RecyclerView] 嵌套到 [androidx.viewpager2.widget.ViewPager2] 左右滑动冲突
- 目前只解决了左右滑动冲突
*/
class RecyclerViewAtViewPager2 : RecyclerView {
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
var x1 = 0f
var x2 = 0f
override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
if(event!!.action == MotionEvent.ACTION_DOWN) {
x1 = event.x
} else if(event.action == MotionEvent.ACTION_MOVE) {
x2 = event.x
} else if (event.action == MotionEvent.ACTION_CANCEL
|| event.action == MotionEvent.ACTION_UP) {
x2 = 0f
x1 = 0f
}
val xOffset= x2-x1
if (layoutManager is LinearLayoutManager) {
val linearLayoutManager = layoutManager as LinearLayoutManager
if (linearLayoutManager.orientation == HORIZONTAL) {
if ((xOffset <= 0 && canScrollHorizontally(1))
|| (xOffset >= 0 && canScrollHorizontally(-1))) {
this.parent?.requestDisallowInterceptTouchEvent(true)
} else {
this.parent?.req