具体思路是利用clipToPadding属性和clipChildren属性
给ViewPager2设置一个内边距padding,添加clipToPadding属性,然后设置clipChildren,让父布局不要限制子View,设置padding后,padding部分的滑动事件不会被内部的RecyclerView收到,所以这里setOnTounchListener,直接交给rv。
viewPager2 = ViewPager2(context).also {
it.setPadding(pLeft.toInt(), pTop.toInt(), pRight.toInt(), pBottom.toInt())
it.clipToPadding = false
it.clipChildren = false
it.setPageTransformer(transferMode)
it.offscreenPageLimit = 2
val rv = it.getChildAt(0).also { v ->
v.overScrollMode = View.OVER_SCROLL_NEVER
}
it.setOnTouchListener { _, event ->
it.performClick()
return@setOnTouchListener rv.onTouchEvent(event)
}
addView(
it, LayoutParams(
LayoutParams.MATCH_PARENT,