Android 多点触控:索引 > 0 的指针不触发 event.Action_Move

Android Multi-touch: Pointers with index > 0 not triggering event.Action_Move

在我的多点触控程序中,我遇到了一个运行时错误,其中指针在屏幕上滑动 (MotionEvent.ACTION_MOVE) 的多点触控逻辑仅由初始指针输入。这意味着我的 case ACTION_MOVE 的 switch 语句中的代码只能由触摸屏幕的第一根手指访问,也就是指针索引 = 0。以下是我的代码的相关部分:

public boolean onTouchEvent(MotionEvent event) {
        // get pointer index from the event object
        int pointerIndex = event.getActionIndex();
        // get pointer ID
        int pointerId = event.getPointerId(pointerIndex);
        // get masked (not specific to a pointer) action
        int maskedAction = event.getActionMasked();

        switch (maskedAction) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN: {
            // We have a new pointer. Lets add it to the list of pointers
            PointF f = new PointF();
            f.x = event.getX(pointerIndex);
            f.y = event.getY(pointerIndex);
            mActivePointers.put(pointerId, f);
            Log.d("Multitouch", "x coord = " + Float.toString(f.x));
            Log.d("Multitouch", "y coord = " + Float.toString(f.y));
            break;
        }
        case MotionEvent.ACTION_MOVE: { // a pointer was moved
            Log.e("Multitouch", "Pointer"+ Integer.toString(pointerId) +" is moving");
            for (int size = event.getPointerCount(), i = 0; i < size; i++) {
                PointF f = mActivePointers.get(event.getPointerId(i));
                if (f != null) {
                    f.x = event.getX(i);
                    f.y = event.getY(i);
                }
            }
            break;
        }
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            mActivePointers.remove(pointerId);
            break;
        }
        }
        invalidate();
        return true;
    }

不用说我希望 Action_Move 中的代码由任何指针触发,而不仅仅是初始指针。是什么阻止索引零以外的指针触发移动事件?

如文档中所述,MotionEvent.getActionIndex() 仅 return 是 ACTION_POINTER_UPACTION_POINTER_DOWN (http://developer.android.com/reference/android/view/MotionEvent.html#getActionIndex%28%29) 的索引。但是,您在日志输出中使用由所述函数编辑的指针索引 return 生成的指针 ID。因此,日志不正确,因为该函数没有 return 您所期望的。