TouchEvent
事件传递
- 方法A:
dispatchTouchEvent:
- 方法B:
onInterceptTouchEvent
:这个方法比较复杂 方法C:
onTouchEvent
1.You will receive the down event here.
每次down事件都不管parent返回值,都会往下传递
2.The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
这段是比较复杂的描述,一旦你return true,你将不会在这个方法中获得剩下的event(除了cancel)(但是测试发现父类retrun true 且onTouchEvent也return true,子类也换回true时,父类仍然能够接受到所以event)父B return false 子B return true:子C return true 则 父C方法将不会被调用 子B也接受不到剩下的event,父B仍然能够接受到剩下的event
- 父B return false 子B return true:子C return false,则只有父A/C接受到剩下的event
- 父B return false 子B return false 子C return true 则 子A/C, 父A/B会接受剩下的event
requestDisallowInterceptTouchEvent
使用
子类可以调用分类这个方法,当子类自身不消费
Event
时,参数传true
时,则父控件不会继续传递和消费改event
改技巧当嵌套使用时,有时需要父控件拦截
event
,有时不需要父控件拦截,比较使用