1

I'm having some trouble with android's multi-touch system. I've been to their docs about how it works and from that I thought this bit of code here might work (note, pointers is an array of points so that I may track each point by ID) however, I found that when it came to dragging, it only would update the pointer with ID 0. I'm not sure whats going wrong here, could someone please help me? (also worth noting, this method is called from the onTouch() event in another class and yes, it returns true :) )

public void tap(MotionEvent e) {
    int index = MotionEventCompat.getActionIndex(e);
    int ID = MotionEventCompat.getPointerId(e, index);
    switch(MotionEventCompat.getActionMasked(e)) {
    case MotionEvent.ACTION_DOWN:
        pointers[ID] = new Point((int)MotionEventCompat.getX(e, index), (int)MotionEventCompat.getY(e, index));
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        pointers[ID] = new Point((int)MotionEventCompat.getX(e, index), (int)MotionEventCompat.getY(e, index));
        break;
    case MotionEvent.ACTION_MOVE:
        pointers[ID] = new Point((int)MotionEventCompat.getX(e, index), (int)MotionEventCompat.getY(e, index));
        break;
    case MotionEvent.ACTION_UP:
        pointers[ID] = new Point((int)MotionEventCompat.getX(e, index), (int)MotionEventCompat.getY(e, index));
        break;
    }
}
4

1 回答 1

1

The ID 0 is correct, because you just use one finger to drag. The pointer means your finger. The index here should always be 0 too in your scenario. In addition, you just need to use MotionEvent e, such as

e.getPointerCount ();
e.getX (pointerIndex);
e.getY (pointerIndex);
于 2013-09-30T02:11:57.557 回答