关于requestDisallowInterceptTouchEvent()的正确用法
来源:互联网 发布:流畅的python怎么样 编辑:程序博客网 时间:2024/06/05 02:27
requestDisallowInterceptTouchEvent(true)方法是用来子View告诉父容器不要拦截我们的事件的,但是这个代码放的位置很重要,可能导致失效。首先我们要知道父类肯定能收到Down事件的,因为这个是事件的起源,系统默认在VIewGroup里把requestDisallowInterceptTouchEvent里把子View对于Down事件的拦截权利剥削了,有了这个Down,它才会决定后面的事件是否传给子类,看父类代码
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: return false; case MotionEvent.ACTION_MOVE: //表示父类需要 if(true) { return true; } else { return false; } case MotionEvent.ACTION_UP: return true; default: break; } // TODO Auto-generated method stub Log.e("TestView","父容器拦截"); return false; //如果设置拦截,除了down,其他都是父类处理 }代码可以看出,父类拦截了move和up事件,我们怎么让他失效呢,答案是在接受到down事件的方法里,而不是一开始就设置这个true标志,为什么呢,因为Viewgroup会在收到down事件时重置这个标志,如果太早设置就无效了。
0 2
- 关于requestDisallowInterceptTouchEvent()的正确用法
- 关于ViewGroup中requestDisallowInterceptTouchEvent的用法
- requestDisallowInterceptTouchEvent的用法
- requestDisallowInterceptTouchEvent的用法
- View事件分发机制——requestDisallowInterceptTouchEvent的用法
- 关于宏的正确用法和错误用法
- android requestDisallowInterceptTouchEvent的用途
- requestDisallowInterceptTouchEvent(true)的使用
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- 去掉IE10、IE11的默认文本框样式
- PCA和whitening
- 【bzoj1345】【序列问题】【贪心】
- 嗨,代代代码
- IOS UIAlertController 弹框 (iOS 9.0 后代替了UIAlertView弹框 和 UIActionSheet下弹框)
- 关于requestDisallowInterceptTouchEvent()的正确用法
- android中extends 和implements
- css工具
- AndroidStudio小技巧
- xx-net如何添加appid
- Easyui Datagrid 排序
- Letter Combinations of a Phone Number 电话按键的组合
- 内网和外网之间的通信
- 黑客内核:编写属于你的第一个Linux内核模块