requestDisallowInterceptTouchEvent 不好用

_OUTMAN_ 发布于 2016/06/02 16:21
阅读 662
收藏 0
我在内层类中使用requestDisallowInterceptTouchEvent还是会执行外层的onIntercept方法,是我demo的用法不对吗?下面是两个类的详细代码。
public class ViewParent extends LinearLayout {

	public ViewParent(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public ViewParent(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		switch (ev.getAction() & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_DOWN:
				println("onInterceptTouchEvent", "ACTION_DOWN");
				break;
			case MotionEvent.ACTION_MOVE:
				println("onInterceptTouchEvent", "ACTION_MOVE");
				break;
			case MotionEvent.ACTION_UP:
				println("onInterceptTouchEvent", "ACTION_UP");
				break;
		}
		return true;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction() & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_DOWN:
				println("onTouchEvent", "ACTION_DOWN");
				break;
			case MotionEvent.ACTION_MOVE:
				println("onTouchEvent", "ACTION_MOVE");
				break;
			case MotionEvent.ACTION_UP:
				println("onTouchEvent", "ACTION_UP");
				break;
		}
		return true;
	}
	
	void println(String tag, String msg) {
		Log.d("ViewParent:" + tag, msg);
	}

}


public class ViewChild extends Button {

	public ViewChild(Context context) {
		super(context);
	}
	public ViewChild(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction() & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_DOWN:
				getParent().requestDisallowInterceptTouchEvent(true);
				println("onTouchEvent", "ACTION_DOWN");
				break;
			case MotionEvent.ACTION_MOVE:
				println("onTouchEvent", "ACTION_MOVE");
				break;
			case MotionEvent.ACTION_UP:
				getParent().requestDisallowInterceptTouchEvent(false);
				println("onTouchEvent", "ACTION_UP");
				break;
		}
		return true;
	}
	
	void println(String tag, String msg) {
		Log.d("ViewChild:" + tag, msg);
	}
}





加载中
0
_
_OUTMAN_
为什么没人回答呢?太简单了吗?
返回顶部
顶部