事件冲突,无非就是嵌套着的两个view都能move,
但子view的move事件被ViewGroup的onInterceptTouchEvent()给拦截了,move事件由ViewGroup的OnTouchEvent处理;
解决办法:
在子view的角度,首先看一眼事件的方法的调用顺序*** dispatchTouchEvent() -> onTouch() -> onTouchEvent() -> onLongClick() -> onClick()*** ,
(一)
如果根据这个顺序,在子View的dispatchTouchEvent()的DOWN中,调用 View.getParent().requestDisallowInterceptTouchEvent(true);
(二)
在子view的****onTouch()****中调用
View.getParent().requestDisallowInterceptTouchEvent(****true****);
(三)
因为被拦截了,所以子View的onTouchEvent()的move事件不一定会被调用,
但子view的DOWN事件会被调用,可以在onTouchEvent()的DOWN事件中调用 View.getParent().requestDisallowInterceptTouchEvent(true);
(四)
也可以在ViewGroup的onInterceptTouchEvent()中根据move的滑动距离来判断上下滑还是左右滑,从而进行决定是否拦截,
注意onInterceptTouchEvent的move事件要被触发,需要clickable为true,或子view的clickable为true