首先进入Activity的dispatchTouchEvent方法。默认会调用userInteraction方法,这里你可以重写此方法处理用户每次点击的需求。其次判断此view下面是否还有可以点击的view。若有,返回true把事件分发给下层view没有调用onTouchEvent方法。
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
当然你在重写dispatchTouchEvent方法时可以不调用父类的dispatchTouchEvent方法,这样导致你不会调用当前view的onTouchEvent方法,也不能往下分发事件。