android ViewParent requestDisallowInterceptTouchEvent 测试

来源:互联网 发布:网络看电视软件哪个好 编辑:程序博客网 时间:2024/05/13 20:17

简单测试了一下 requestDisallowInterceptTouchEvent的使用:

两个类:

public static class myView extends View {@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubint action = MotionEventCompat.ACTION_MASK & event.getAction();Log.e("FYF", "myView " + SystemUtils.motionEventToString(event));if (action == MotionEvent.ACTION_DOWN) {getParent().requestDisallowInterceptTouchEvent(true);}return true;}}

public static class myLinearLayout extends LinearLayout {@Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {// TODO Auto-generated method stub//return super.onInterceptTouchEvent(ev);int action = MotionEventCompat.ACTION_MASK & ev.getAction();if (action == MotionEvent.ACTION_DOWN) {return false;} else {return true;}}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubLog.e("FYF", "myLinearLayout " + SystemUtils.motionEventToString(event));return true;}}

在MyLinearLayout里放一个myView,

MyLineaLayout在interceptTouchEvevnt时,如果action 是 ACTION_DOWN, 那么就return false,将event继续传递给myView,

否则就自己直接截获,


myView没有requestDisallowInterceptTouchEvent(true):

E/FYF     (11126): myView ACTION_DOWN
E/FYF     (11126): myView ACTION_CANCEL
E/FYF     (11126): myLinearLayout ACTION_MOVE
E/FYF     (11126): myLinearLayout ACTION_MOVE
......................................
E/FYF     (11126): myLinearLayout ACTION_UP


myView 运行了requestDisallowInterceptTouchEvent(true):

E/FYF     (12069): myView ACTION_DOWN
E/FYF     (12069): myView ACTION_MOVE
E/FYF     (12069): myView ACTION_MOVE
......................................
E/FYF     (12069): myView ACTION_UP

0 0
原创粉丝点击