截取自《Android开发艺术探索》
三个重要方法:
public boolean dispatchTouchEvent(MotionEvent ev);
事件分发,return true向子view传递,return false传递到父view
public boolean onInterceptToucherEvent(MotionEvent ev);
判断是否拦截事件,return true由本view处理,return false传递到子view
public boolean onTouchEvent(MotionEvent ev);
处理touch事件,return true本view消耗事件,return false传递到父view继续处理
伪代码关系:
public boolean dispatchTouchEvent(MotionEvent ev) {
boolean consume = false;
if (onInterceptTouchEvent(ev)) {
consume = onTouchEvent(ev);
} else {
consume = child.dispatchTouchEvent(ev);
}
return consume;
}
824

被折叠的 条评论
为什么被折叠?



