您的位置:首页 > 移动开发 > Android开发

android View事件传递

2016-01-26 18:51 609 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息