所以,我在这里完成了关于这个问题的所有讨论。我返回 true,没有其他地方可以处理 ACTION_UP。
我使用线程来处理图形和计算,尽管我不知道为什么这很重要。
这是我对 onTouch 方法的实现:
@Override
public boolean onTouch(View v, MotionEvent event) {
synchronized (this) {
int action = event.getAction() & MotionEvent.ACTION_MASK;
int pointerIndex = event.getAction()
& MotionEvent.ACTION_POINTER_INDEX_MASK >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
int pointerCount = event.getPointerCount();
TouchEvent touchEvent;
for (int i = 0; i < MAX_TOUCHPOINTS; i++) {
if (i >= pointerCount) {
isTouched[i] = false;
id[i] = -1;
continue;
}
int pointerId = event.getPointerId(i);
if ((event.getAction() != MotionEvent.ACTION_MOVE && i != pointerIndex)) {
// if its an up/down/cancel/out event mask the id to see if
// we should process it for this touch point
continue;
}
Log.i("Logged TouchEvents", "" + event.getAction());
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
touchEvent = touchEventPool.newObject();
touchEvent.type = TouchEvent.TOUCH_DOWN;
touchEvent.pointer = pointerId;
touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
isTouched[i] = true;
id[i] = pointerId;
toucheventBuffer.add(touchEvent);
Log.d("MultiTouchHandler", "TouchEvent.Down ("
+ touchEvent.x + "," + touchEvent.y + ")");
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL:
touchEvent = touchEventPool.newObject();
touchEvent.type = TouchEvent.TOUCH_UP;
touchEvent.pointer = pointerId;
touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
isTouched[i] = false;
id[i] = -1;
toucheventBuffer.add(touchEvent);
Log.d("MultiTouchHandler", "TouchEvent.TouchUp ("
+ touchEvent.x + "," + touchEvent.y + ")");
break;
case MotionEvent.ACTION_MOVE:
touchEvent = touchEventPool.newObject();
touchEvent.type = TouchEvent.TOUCH_DRAG;
touchEvent.pointer = pointerId;
touchEvent.x = touchX[i] = (int) (event.getX() * scaleX);
touchEvent.y = touchY[i] = (int) (event.getY() * scaleY);
isTouched[i] = true;
id[i] = pointerId;
toucheventBuffer.add(touchEvent);
Log.d("MultiTouchHandler", "TouchEvent.TouchDrag ("
+ touchEvent.x + "," + touchEvent.y + ")");
break;
default:
break;
}
}
}
return true;
}
请注意,变量 'action'(在 switch/case 之前检查)永远不会等于 1(ACTION_UP)
提前致谢。