美文网首页
onInterceptTouchEvent调用情况分析

onInterceptTouchEvent调用情况分析

作者: 土豆肉多 | 来源:发表于2016-12-09 11:29 被阅读0次

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行)

相关文章

网友评论

      本文标题:onInterceptTouchEvent调用情况分析

      本文链接:https://www.haomeiwen.com/subject/jvyemttx.html