对Android Activity ViewGroup View的事件的分发测试


对事件的分发支持如下:

####### 这里的View是只textview类似的不能有子View的View,不是最大的父类View.
重写textview的时候 可以继承到dispatchTouchEvent 这是从View里面拿到的

textview类似的view里面没有这个方法 也就不会处理 但你继承了 就会处理

ACTION_CANCEL的执行 只是在你滑动超过了这个控件之外的时候 才会触发

每个轮流执行下去的都会执行ACTION_DOWN 但是只有最后处理事件的地方或者返回true的地方才会执行move和up 事件

所谓消费了此事件就是down move up都执行了 其他的 都只会执行一个down事件








ActivityViewGroupView
dispatchTouchEvent YesYesYes
onInterceptTouchEvent NoYesNo
onTouchEvent YesYesYes

顺序是Activity——>ViewGroup——>View

如果都返回Super默认值 执行的逻辑是

Activity onTouchEvent 返回true 返回false 他们都一样

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View dispatchTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

(dispatchTouchEvent和onTouchEvent的ACTION_MOVE 会顺序一起执行多次)

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

Activity dispatchTouchEvent 返回true 或者false 其他都默认

####### dispatchTouchEvent这里的 true 或者false是一样的结果 都会拦截 只有默认的不会拦截

Activity dispatchTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity dispatchTouchEvent ACTION_UP

一个down一个up中间全是move 别的都不会执行

View dispatchTouchEvent 返回true 其他都默认

所有的onTouchEvent 都不会执行 其余的全部执行

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View dispatchTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

ViewGroup dispatchTouchEvent ACTION_MOVE

ViewGroup onInterceptTouchEvent ACTION_MOVE

View dispatchTouchEvent ACTION_MOVE

Activity dispatchTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent ACTION_UP

ViewGroup onInterceptTouchEvent ACTION_UP

View dispatchTouchEvent ACTION_UP

View dispatchTouchEvent 返回false 其他都默认

这时候 view的onTouchEvent 不会执行 其余的down都会执行

最终由Activity的dispatchTouchEvent和onTouchEvent执行ACTION_MOVE和最终的ACTION_UP

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View dispatchTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

View onTouchEvent 返回true 其他都默认

Activity和ViewGroup的onTouchEvent不会执行 别的全部动作都执行

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View dispatchTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

ViewGroup dispatchTouchEvent ACTION_MOVE

ViewGroup onInterceptTouchEvent ACTION_MOVE

View dispatchTouchEvent ACTION_MOVE

View onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent ACTION_UP

ViewGroup onInterceptTouchEvent ACTION_UP

View dispatchTouchEvent ACTION_UP

View onTouchEvent ACTION_UP

View onTouchEvent 返回false 其他都默认 所有的down都会执行

最终由Activity的dispatchTouchEvent和onTouchEvent执行ACTION_MOVE和最终的ACTION_UP

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View dispatchTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN


Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent 返回true 其他都默认

这时候只执行了Activity和ViewGroup的dispatchTouchEvent方法

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

ViewGroup dispatchTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent 返回false 其他都默认

这时候 执行了Activity和ViewGroup的dispatchTouchEvent

的ACTION_DOWN方法 之后由还有activity的dispatchTouchEvent和onTouchEvent方法执行到底

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

ViewGroup onInterceptTouchEvent 返回true 其他都默认

这时候 执行了Activity和ViewGroup的所有ACTION_DOWN方法

之后还由activity的dispatchTouchEvent和onTouchEvent方法执行到底

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

ViewGroup onInterceptTouchEvent 返回false 其他都默认

这时候 执行了所有ACTION_DOWN方法

之后还由activity的dispatchTouchEvent和onTouchEvent方法执行到底

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View onInterceptTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP

ViewGroup onTouchEvent 返回true 其他都默认

这时候 activity的ACTION_DOWN不执行 执行了其他的所有ACTION_DOWN方法

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View onInterceptTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

ViewGroup dispatchTouchEvent ACTION_MOVE

ViewGroup onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

ViewGroup dispatchTouchEvent ACTION_UP

ViewGroup onTouchEvent ACTION_UP

ViewGroup onTouchEvent 返回false 其他都默认

这时候 执行了所有ACTION_DOWN方法

之后还由activity的dispatchTouchEvent和onTouchEvent方法执行到底

Activity dispatchTouchEvent ACTION_DOWN

ViewGroup dispatchTouchEvent ACTION_DOWN

ViewGroup onInterceptTouchEvent ACTION_DOWN

View onInterceptTouchEvent ACTION_DOWN

View onTouchEvent ACTION_DOWN

ViewGroup onTouchEvent ACTION_DOWN

Activity onTouchEvent ACTION_DOWN

Activity dispatchTouchEvent ACTION_MOVE

Activity onTouchEvent ACTION_MOVE

……

Activity dispatchTouchEvent ACTION_UP

Activity onTouchEvent ACTION_UP