标签:
外部拦截法解决滑动冲突
声明成员变量:
/** * 处理滑动冲突的属性 */ 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