码迷,mamicode.com
首页 > 其他好文 > 详细

滑动冲突

时间:2016-04-16 19:20:54      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:


外部拦截法解决滑动冲突

声明成员变量:

/**
	 * 处理滑动冲突的属性
	 */
	private int mLastIntercepX = 0;
	private int mLastIntercepY = 0;



//外部拦截法处理滑动冲突
	public boolean onInterceptTouchEvent(MotionEvent event) {
		boolean intercept = false;
		int x = (int) event.getX();
		int y = (int) event.getY();

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			intercept = false;
			break;
		case MotionEvent.ACTION_MOVE:
			int deltaX= (int) (x-mLastIntercepX);
			int deltaY= (int) (y-mLastIntercepY);
			if(Math.abs(deltaX)>Math.abs(deltaY)){//左右滑动
				intercept = true;
			}
			else {//上下滑动,交给子View处理
					intercept = false;
				
			}
			break;
		case MotionEvent.ACTION_UP:
			intercept = false;
			break;
		}

		mLastIntercepX = x;
		mLastIntercepY = y;

		return intercept;
	}


滑动冲突

标签:

原文地址:http://blog.csdn.net/wei_chong_chong/article/details/51161932

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!