requestDisallowInterceptTouchEvent
来源:互联网 发布:手机有学编程的吗 编辑:程序博客网 时间:2024/05/12 19:48
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
- 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
- sql server 2008服务器连接报错
- Android高效率编码-findViewById()的蜕变-注解,泛型,反射
- android 小细节1
- Linux初始化init系统
- maven部署web应用的两种方式
- requestDisallowInterceptTouchEvent
- leetcode笔记:Longest Substring Without Repeating Characters
- 引用
- ongl和一些标签
- 正则表达式学习
- jQuery插件学习(1)——分页控件
- 【jQuery】:hidden过滤选择器
- 科研感悟与方法
- javaDoc标签