requestDisallowInterceptTouchEvent
来源:互联网 发布:众安保险尊享e生 知乎 编辑:程序博客网 时间:2024/06/06 15:03
requestDisallowInterceptTouchEvent
Posted on 2013-06-22 23:06 喜糖 阅读(300) 评论(0) 编辑 收藏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 }
当用户按下的时候,我们告诉父组件,不要拦截我的事件(这个时候子组件是可以正常响应事件的),拿起之后就会告诉父组件可以阻止。
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent
- 【Android】requestDisallowInterceptTouchEvent
- Android requestDisallowInterceptTouchEvent
- requestDisallowInterceptTouchEvent---1
- requestDisallowInterceptTouchEvent---2
- requestDisallowInterceptTouchEvent方法
- android ViewParent requestDisallowInterceptTouchEvent 测试
- android requestDisallowInterceptTouchEvent的用途
- Android TouchEvent之requestDisallowInterceptTouchEvent
- 怎么把自己的windows7电脑做无线发射器
- 8.4 内部排序法---归并类排序
- hdu4708
- 深度优先搜索
- 竖直滑动的viewpager-------VerticalAdapter
- requestDisallowInterceptTouchEvent
- POJ 2175 spfa费用流消圈
- MapReduce调度与执行原理之作业初始化
- 自我工作中常用的Linux命令记录
- JAVA String.format 方法使用介绍
- ORACLE FLASHBACK DROP 知识整理
- Android 浏览器自定义scheme:market://协议
- 文本相似度算法(余弦定理)
- gdb调试器的常用命令