override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
ev?.let {
var parent=this.parent
while (parent !is ViewParent){
parent=parent.parent
if(parent==null){
throw Throwable("can not find viewpager in recyclerview")
}
}
if(ev.action==MotionEvent.ACTION_DOWN) {
lastX=ev.x
lastY=ev.y
}else if(ev.action==MotionEvent.ACTION_MOVE){
//如果是竖向滑动则禁止viewpager拦截,否则继续分发
if((ev.y-lastY).absoluteValue>=(ev.x-lastX).absoluteValue){
parent.requestDisallowInterceptTouchEvent(true)
}else{
parent.requestDisallowInterceptTouchEvent(false)
}
}else if(ev.action==MotionEvent.ACTION_UP){
parent.parent.requestDisallowInterceptTouchEvent(false)
}
}
return super.dispatchTouchEvent(ev)
}
android bottomsheetdialog viewpager嵌套recyclerview滑动冲突解决
猜你喜欢
转载自blog.csdn.net/a1663049254/article/details/130546012
今日推荐
周排行