Android多点触控 – 第二手指ACTION.MOVE忽略

下面的代码是我一直在尝试用于多点触控的。 当我拖动我的手指时,手指一个被正确设置并移动。 当我触摸并释放我的手指时,手指两出现并消失,但它不会四处移动。 任何想法有什么不对?

我已经阅读开发者博客我还是不明白是什么问题。

@Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction() & MotionEvent.ACTION_MASK; int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; int pointerId = event.getPointerId(pointerIndex); switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: if (pointerId == 0) { fingerOneDown = 1; fingerOneX = event.getX(pointerIndex); fingerOneY = event.getY(pointerIndex); } if (pointerId == 1) { fingerTwoDown = 1; fingerTwoX = event.getX(pointerIndex); fingerTwoY = event.getY(pointerIndex); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_CANCEL: if (pointerId == 0) { fingerOneDown = 0; fingerOneX = event.getX(pointerIndex); fingerOneY = event.getY(pointerIndex); } if (pointerId == 1) { fingerTwoDown = 0; fingerTwoX = event.getX(pointerIndex); fingerTwoY = event.getY(pointerIndex); } break; case MotionEvent.ACTION_MOVE: if (pointerId == 0) { fingerOneDown = 1; fingerOneX = event.getX(pointerIndex); fingerOneY = event.getY(pointerIndex); } if (pointerId == 1) { fingerTwoDown = 1; fingerTwoX = event.getX(pointerIndex); fingerTwoY = event.getY(pointerIndex); } break; } return true; } 

Solutions Collecting From Web of "Android多点触控 – 第二手指ACTION.MOVE忽略"

没关系 我修好了它。 由于一些奇怪的原因,ACTION.MOVE事件总是作为pointerId得到零。 因此,您必须重新计算事件中的指针Id,如下所示:

  case MotionEvent.ACTION_MOVE: int pointerCount = event.getPointerCount(); for(int i = 0; i < pointerCount; ++i) { pointerIndex = i; pointerId = event.getPointerId(pointerIndex); Log.d("pointer id - move",Integer.toString(pointerId)); if(pointerId == 0) { fingerOneDown = 1; fingerOneX = event.getX(pointerIndex); fingerOneY = event.getY(pointerIndex); } if(pointerId == 1) { fingerTwoDown = 1; fingerTwoX = event.getX(pointerIndex); fingerTwoY = event.getY(pointerIndex); } } break;