onInterceptTouchEvent是ViewGroup独有的触碰事件截取方法。默认返回值是false。晚上一般的解释是此方法返回true,则dispatchTouchEvent方法不继续下发,直接调用onTouchEvent方法。下面从简单的几行源码来具体分析一下:
<pre>
// Check for interception.final boolean intercepted;
if (actionMasked == MotionEvent.ACTION_DOWN || mFirstTouchTarget != null) {
final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0;
if (!disallowIntercept) {
intercepted = onInterceptTouchEvent(ev);
ev.setAction(action); // restore action in case it was changed
} else {
intercepted = false;
}
} else {
// There are no touch targets and this action is not an initial down
// so this view group continues to intercept touches.
intercepted = true;
}
</pre>
(注:6.0版本源码ViewGroup类dispatchTouchEvent方法中,2102-2117行)
网友评论