Android视图消息传递

来源:互联网 发布:我的世界凋零风暴js 编辑:程序博客网 时间:2024/06/04 23:06

1.dispatchTouchEvent(MotionEvent ev):用于事件分发。

2.onInterceptTouchEvent(MotionEvent ev):用于拦截事件

3.onTouchEvent(MotionEvent e):

事件首先会传入dispatchTouchEvent(MotionEvent ev):判断当前布局(ViewGroup)是否需要此事件

若onInterceptTouchEvent(MotionEvent ev) 返回true。则调用当前布局(ViewGroup)的onTouchEvent(MotionEvent ev);

     返回false: 则向子布局(ViewGroup)传递事件 dispatchTouchEvent(MotionEvent ev)

进行接收,继续判断是否需要此事件。当到达最后一个包含子控件(View)的布局时,子控件没有拦截事件的方法,

子控件 dispatchTouchEvent(MotionEvent ev)接收到事件后执行 onTouchEvent(MotionEvent e);

若onTouchEvent(MotionEvent e)没有消耗此事件,则向上一级回传至onTouchEvent(MotionEvent e)若还没有消耗

此事件,则再向上回传。若消耗掉,则终止。


0 0
原创粉丝点击