Android触摸事件传递
来源:互联网 发布:淘宝网宋大师旗舰店 编辑:程序博客网 时间:2024/03/29 00:26
1、前提:
(1).自定义类MyLayout继承于LinearLayout,重写dispatchTouchEvent,onInterceptTouchEvent,onTouchEvent方法
自定义类MyTextView继承于TextView,重写dispatchTouchEvent,onTouchEvent方法
(2).布局文件中:MyTextView在MyLayout中
(3).Activity中MyLayout,MyTextView均设置ontouchListener,实现ontouch方法;
(4).Activity自己也实现dispatchTouchEvent,onTouchEvent方法
2、概念:View自身处理touch流程,先执行setOnTouchListener里面的onTouch,返回false则执行自身View的onTouchEvent,否则不执行自身View的onTouchEvent
3、传递过程:从Acticity->最上层容器View->内部子View....->上层容器View...->最上层容器View-->Activity
执行过程:
(1)当点击MyTextView时:事件会通过Act的dispatch,将事件传到布局文件的顶层View,也就是MyLayout,
(2)执行MyLayout的dispatch方法,如果,dispatch返回false,则将继续执行onIntercept,如果onIntercept返回false,则touch事件传递到子View并执行第三步,否则执行自身 View处理流程
(3)如果子View是ViewGroup则同第(2)步,否则调用自身的dispatch,返回true则事件执行完毕,否则执行自身View处理流程
返回过程:返回条件:如果有任何一个方法返回true,则不再向上返回,
当到达最内层的子View,执行自身处理touch流程后,如果满足返回条件,则返回上一层View的自身处理touch流程,一直到Activity的onTouchEvent事件;
本文参考:http://www.cnblogs.com/yeshenyuege/articles/2415000.html
(1).自定义类MyLayout继承于LinearLayout,重写dispatchTouchEvent,onInterceptTouchEvent,onTouchEvent方法
自定义类MyTextView继承于TextView,重写dispatchTouchEvent,onTouchEvent方法
(2).布局文件中:MyTextView在MyLayout中
(3).Activity中MyLayout,MyTextView均设置ontouchListener,实现ontouch方法;
(4).Activity自己也实现dispatchTouchEvent,onTouchEvent方法
2、概念:View自身处理touch流程,先执行setOnTouchListener里面的onTouch,返回false则执行自身View的onTouchEvent,否则不执行自身View的onTouchEvent
3、传递过程:从Acticity->最上层容器View->内部子View....->上层容器View...->最上层容器View-->Activity
执行过程:
(1)当点击MyTextView时:事件会通过Act的dispatch,将事件传到布局文件的顶层View,也就是MyLayout,
(2)执行MyLayout的dispatch方法,如果,dispatch返回false,则将继续执行onIntercept,如果onIntercept返回false,则touch事件传递到子View并执行第三步,否则执行自身 View处理流程
(3)如果子View是ViewGroup则同第(2)步,否则调用自身的dispatch,返回true则事件执行完毕,否则执行自身View处理流程
返回过程:返回条件:如果有任何一个方法返回true,则不再向上返回,
当到达最内层的子View,执行自身处理touch流程后,如果满足返回条件,则返回上一层View的自身处理touch流程,一直到Activity的onTouchEvent事件;
本文参考:http://www.cnblogs.com/yeshenyuege/articles/2415000.html
- android触摸事件传递
- Android触摸事件传递
- android触摸事件传递
- Android 触摸事件传递
- Android 触摸事件传递机制
- 关于Android触摸事件传递
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- Android 触摸事件传递机制
- android 触摸事件传递机制
- android 触摸事件传递图解
- android触摸事件传递机制
- Android触摸事件传递流程图
- Android 触摸事件传递机制
- Android触摸事件传递机制
- Android触摸事件传递机制
- eclipse启动时无法创建java虚拟机
- 拥有线程安全和阻塞功能的vector类SemVector(LINUX平台)
- Log4j 日志级别
- 从rails升级到gem uninstall,gem cleanup与安装指定版本rails
- android ndk 编译 protobuf-2.5.0
- Android触摸事件传递
- [嵌入式]移植到纯净版本的uboot1.1.6过程--OK6410
- 使用PJSIP库,获得当前时间
- flex传递参数-------TitleWindow向主页面传递参数(2)
- Oracle 删除用户和表空间
- powerpoint 2007 中怎么插入flash动画
- error LNK2019:unresolved external symbol的解决方法
- $0,$1,$2 and set - in shell ,awk ,sed,function ,perl
- python 系统学习笔记(六)---元组