wangsongbin的专栏

假设:View是包含在ViewGroup当中的,则一些方法的执行顺序是:

ViewGroup.dispatchTouchEvent ——》ViewGroup.onInterceptTouchEvent——》View.dispatchTouchEvent——》View.onTouchEvent

一, 正常情况下:ViewGroup.dispatchTouchEvent事件中的一些执行方法:

Event.Action_down:

ViewGroup会捕获事件,如果disallowIntercept为true,ViewGroup.onInterceptTouchEvent返回false,则遍历在当前坐标x,y下的子View;

并将mMotionTarget=child,然后执行:View.dispatchTouchEvent。

Event.Action_move:

ViewGroup会捕获事件,如果disallowIntercept为true,ViewGroup.onInterceptTouchEvent返回false,则执行child.DispatchTouchEvent。

Event.Action_up:

ViewGroup会捕获事件,如果disallowIntercept为true,ViewGroup.intercepttouchevent返回false,则执行child.dispatchTouchEvent。

二, ViewGroup可以通过ViewGroup.requestDisallowIntercept(boolean aa)方法设置disallowIntercept的值。

aa为true不允许拦截,,为false允许拦截。

三,如果要精细到具体拦截那个事件的动作(Event.Action_down。。。。)

可以复写ViewGroup的onInterceptTouchEvent方法

@Override 02. public boolean onInterceptTouchEvent(MotionEvent ev) 03. { 04.int action = ev.getAction(); 05.switch (action) 06.{ 07.case MotionEvent.ACTION_DOWN: 08.//如果你觉得需要拦截 09.return true ; 10.case MotionEvent.ACTION_MOVE: 11.//如果你觉得需要拦截 12.return true ; 13.case MotionEvent.ACTION_UP: 14.//如果你觉得需要拦截 15.return true ; 16.}

注意的是如果,你再Action_Down时return true,则Action_Move,和Action_up都会被屏蔽。在Action_Move时,return true,Action_up会被屏蔽。因为在

ViewGroup.onInterceptTouchEvent方法返回true时,mMotionTarget会被置为null;

如果子View不想被父ViewGroup屏蔽,可一个在disPatchTouchEvent方法中加上:getParent().requestDisallowIntercept(true);

每个人的生命都是可以绽放美丽,只要你珍惜。

wangsongbin的专栏

相关文章:

你感兴趣的文章:

标签云: