Android requestDisallowInterceptTouchEvent
来源:互联网 发布:淘宝网不能正常显示 编辑:程序博客网 时间:2024/05/16 19:34
转自:http://www.cnblogs.com/xitang/archive/2013/06/22/3150380.html
ViewPager来实现左右滑动切换tab,如果tab的某一项中嵌入了水平可滑动的View就会让你有些不爽,比如想滑动tab项中的可水平滑动的控件,却导致tab切换。
因为Android事件机制是从父View传向子View的,可以去检测你当前子View是不是在有可滑动控件等,决定事件是否拦截,但是这个麻烦,而且并不能解决所有的问题(必须检测触摸点是否在这个控件上面),其实有比较简单的方法,在你嵌套的控件中注入ViewPager实例(调用控件的getParent()方法),然后在onTouchEvent,onInterceptTouchEvent,dispatchTouchEvent里面告诉父View,也就是ViewPager不要拦截该控件上的触摸事件。
1 requestDisallowInterceptTouchEvent(true)
代码一般如下:
1 public boolean onTouch(View v, MotionEvent event) { 2 switch (event.getAction()) { 3 case MotionEvent.ACTION_MOVE: 4 pager.requestDisallowInterceptTouchEvent(true); 5 break; 6 case MotionEvent.ACTION_UP: 7 case MotionEvent.ACTION_CANCEL: 8 pager.requestDisallowInterceptTouchEvent(false); 9 break;10 }11 }
当用户按下的时候,我们告诉父组件,不要拦截我的事件(这个时候子组件是可以正常响应事件的),拿起之后就会告诉父组件可以阻止。
0 0
- 【Android】requestDisallowInterceptTouchEvent
- Android requestDisallowInterceptTouchEvent
- android ViewParent requestDisallowInterceptTouchEvent 测试
- android requestDisallowInterceptTouchEvent的用途
- Android TouchEvent之requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- android requestDisallowInterceptTouchEvent()使用时机问题?
- android 事件处理机制之requestDisallowInterceptTouchEvent
- android 事件处理机制之requestDisallowInterceptTouchEvent
- Android相机、相册获取图片显示并保存到SD卡
- android 权限列表 和 理解与使用自定义权限
- 《精通Linux设备驱动程序开发》——音频驱动程序
- qemu-kvm-1.1.0源码中关于迁移的代码分析
- sql server2005学习脚本4-数据查询
- Android requestDisallowInterceptTouchEvent
- Java输入流之BufferReader和Scanner的用法!
- Oracle学习技巧
- bug:EditText 只能输入不能删除修改
- unity3d shader编程中GrabPass 在某些android手机上失效的解决方案
- HTTP协议详解
- 世界的尽头
- mp4文件格式系列1 - 综述
- 玩转shell之符号篇