LZN LZN -3 years ago 231
Android Question

Get MotionEvent.getRawX/getRawY of other pointers

Can I get the value of MotionEvent.getRawX()/getRawY() of other pointers ?

MotionEvent.getRawX() api reference

The api says that uses getRawX/getRawY to get original raw X/Y coordinate, but it only for 1 pointer(the last touched pointer), is it possible to get other pointer's raw X/Y coordinate ?

Answer Source

Indeed, the API doesn't allow to do this, but you can compute it. Try that :

public boolean onTouch(final View v, final MotionEvent event) {

    int rawX, rawY;
    final int actionIndex = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
    final int location[] = { 0, 0 };
    v.getLocationOnScreen(location);
    rawX = (int) event.getX(actionIndex) + location[0];
    rawY = (int) event.getY(actionIndex) + location[1];

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download