Вопрос

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;
    }
}
Это было полезно?

Решение

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top