@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.v(tag,"-----"+getClass().getSimpleName()+" ,onInterceptTouchEvent: "+getStrAction(ev));
int action = ev.getAction();
if(action == MotionEvent.ACTION_MOVE){
return true;
}
boolean ret = super.onInterceptTouchEvent(ev);
Log.v(tag,"-----"+getClass().getSimpleName()+" ,onInterceptTouchEvent: "+getStrAction(ev)+" -> "+ret);
return ret ;
}
touch 事件序列:一般包含一个action_down,N个action_move,一个action_up 或者 一个action_cancel;
情况一,在一次touch事件序列中,父viewgroup对action_down 不拦截,而子view 对action_down事件消费返回为true后,若父viewgroup 对该touch事件序列中后续的action_move 拦截为true时,无论父viewgroup 的onTouchEvent方法返回结果是true 或者false,子view将收到一个action_cancel 事件,表示该touch事件序列将被父viewgroup拦截,不再传递给该子view。但不影响子view接受下一次touch事件序列
本文解析了Android中Touch事件的处理流程,重点介绍了当父ViewGroup对Touch事件序列中的ACTION_MOVE进行拦截时,子View会收到ACTION_CANCEL事件的情况,并讨论了不同情况下Touch事件的传递机制。
462

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



