android View事件传递

来源:互联网 发布:淘宝网书店 编辑:程序博客网 时间:2024/06/03 15:56

1:首先调用父类的LinearLayout/RelativeLayout 的dispatchTouchevent(MotionEvent event)进行事件的分发

(1):返回true:处理事件

(2):返回false,交给自己的onTouchEvent进行处理

(3):返回:return super.dispatchTouchEvent(ev);调用子View的dispathTouchevent(MotionEvent  event);

如果子view为ViewGroup,继续遵循上述处理方式进行处理,如果子view为具体view,

2: 调用子view(具体的view,如button,TextView,ImageView等)的dispatchTouchevent(MotionEvent event)进行处理,

(1)返回ture,处理事件,不往下传递

(2)返回false,交给onTouchEvent(MotionEvent event)处理

(3)返回super.dispatchTouchevent(MotionEvent event)与返回false一样,

注意:如果在Action.Down的时候,onTouchEvent(MotionEvent event)返回false,则后续的Action.MOVE,和Action.UP不会继续到底此View

<=======================================================================================>

附件有测试demo

0 0