1,传递机制主要原理
onTouchevent(处理事件) ,dispatchTouchEvent(分发),onInterceptTouchEvent(拦截事件)
2,实现效果
【1】正常状态孩子不消费事件,会返回给父容器。
MyViewGroup, dispatchTouchEvent(ture),onInterceptTouchEvent(false), onTouchevent(ture)
MyView dispatchTouchEvent(ture), onTouchevent(false)
父容器先获取事件,不拦截,分发给孩子,孩子接收到事件.孩子也不消费事件.把事件又返回给父容器消费,默认父容器也不消费
【2】孩子消费事件,传递结束
MyViewGroup, dispatchTouchEvent(ture),onInterceptTouchEvent(false), onTouchevent(ture)
MyView dispatchTouchEvent(ture), onTouchevent(ture)
父容器先获取事件.不拦截.分发给孩子.孩子接收到事件.让孩子消费事件.如果事件消费了,事件传递结束
【3】父容器先获取事件.拦截.事件不会分发给孩子.让父容器自己消费
MyViewGroup, dispatchTouchEvent(ture),onInterceptTouchEvent(ture), onTouchevent(ture)
MyView dispatchTouchEvent(ture), onTouchevent(ture)
【4】父容器先获取事件.点击绿色区域.不会把事件分发给孩子.父容器拦截
MyViewGroup, dispatchTouchEvent(ture),onInterceptTouchEvent(ture), onTouchevent(ture)
MyView dispatchTouchEvent(ture), onTouchevent(ture)
【5】父容器先获取事件.点击绿色区域.不会把事件分发给孩子.父容器不拦截
MyViewGroup, dispatchTouchEvent(ture),onInterceptTouchEvent(true), onTouchevent(ture)
MyView dispatchTouchEvent(ture), onTouchevent(ture)
【6】