requestDisallowInterceptTouchEvent
来源:互联网 发布:东华软件 减持 编辑:程序博客网 时间:2024/06/06 13:50
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
- XCODE4.x添加FrameWork
- JQuery $.POST 返回json数据需注意到几点
- 原生JavaScript开篇
- 什么是好的用户体验?
- 网络游戏玩家心理学探讨
- requestDisallowInterceptTouchEvent
- csdn赵老师名言
- opencv c++函数 highgui模块 2 OpenCV的视频输入和相似度测量
- MKMapView确立当前位置并圈定范围
- IOS开发之--拖动图片
- 列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序:
- iOS 正则表达式验证
- JAVA学习笔记(总结)
- 理解EnterCriticalSection 临界区