View 事件传递
来源:互联网 发布:网络电影制作流程 编辑:程序博客网 时间:2024/06/09 16:43
转载自http://a.codekk.com/detail/Android/Trinea/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7%82%B9%E4%B9%8B%20View%20%E4%BA%8B%E4%BB%B6%E4%BC%A0%E9%80%92
贴上自己对onInterceptTouchEvent的一些小结
Android Touch事件假设布局层次为
Layout0
Layout1
Layout2
Layout3
如果谁都没有去interceptTouch,同时谁都没有处理onTouch事件。
那么Layout0->intercept Layout1->intercept Layout2->intercept Layout3->intercept
Layout3->onTouch Layout2->onTouch Layout1->onTouch Layout0->onTouch
由于谁都没有消费ACTION_DOWN事件,后续的MOVE,UP事件将不会传进来。
如果Layout2 intercept了,但是不消费onTouch
那么Layout0->intercept Layout1->intercept Layout2->intercept
Layout2->onTouch Layout1->onTouch Layout0->onTouch
后续事件不会传入
如果Layout2 intercept了,同时消费了。
那么 0->intercept 1->intercept 2->intercept 2->onTouch
0->intercept 1->intercept 2->onTouch
0->intercept 1->intercept 2->onTouch
0->intercept 1->intercept 2->onTouch
如果Layout2 intercept了,不消费,Layout1消费了。
那么0->intercept 1->intercept 2->intercept
2->onTouch 1->onTouch
0->intercept 1->onTouch
0->intercept 1->onTouch
0->intercept 1->onTouch
总结一下。规律就是
如果当前Layout intercept了,那么子View和子ViewGroup都没有机会去获得Touch事件了。如果当前Layout并不消费事件的话,这个事件会一直向上冒泡,直到某个父Layout的onTouchEvent消费了这个事件。如果没有任何一个父Layout消费这个事件,那么后续的事件都不会被接受。
如果在冒泡过程中有某个Layout消费了这个事件。那么这个Layout的所有父Layout的intercept仍然会被调用。但是当前Layout的intercept不会再被调用了。直接调用onTouch事件。
另外,对于底层的View来说,有一种方法可以阻止父层的View截获touch事件,就是调用getParent().requestDisallowInterceptTouchEvent(true);方法。一旦底层View收到touch的action后调用这个方法那么父层View就不会再调用onInterceptTouchEvent了,也无法截获以后的action。在实践过程中发现ListView在滚动的时候会调用这个方法。使得action不能被拦截。
0 0
- View事件传递
- View 事件传递
- View 事件传递
- View 事件传递
- View 事件传递
- View 事件传递
- View的事件传递
- View 事件传递
- Android View 事件传递
- View 事件传递
- view的事件传递
- View 事件传递
- View事件传递机制
- android View事件传递
- View事件传递分析
- view事件传递
- View 事件传递机制
- View事件传递机制
- android so文件加载连接简单理解
- win8.1下安装ubuntu,通过iso文件做双系统步骤,调整引导页
- EL表达式无效?
- 基于公众号服务的预付款会员卡服务系统
- 时间相关
- View 事件传递
- 60.[PHP]PHP简介及LNMP环境搭建(CentOS 7环境)
- 如何解决request.getParameter()取值乱码问题
- PreparedStatement接口详解
- maven私服搭建
- iOS面试常见问题最全梳理
- 二叉树的三种遍历方式的递归实现和迭代实现
- 学习笔记之JavaSE(51)--网络编程3
- HBase安装配置之伪分布式模式