Search code examples
androidtouch

How do I know if a MotionEvent is relative or absolute?


I am implementing OnTouchListener and am receiving MotionEvent objects. Some ACTION_MOVE events reports absolute X/Y coordinates, while some reports relative coordinates.

How can I ask a MotionEvent what kind of coordinates it currently represents?


Solution

  • You may want to use these for absolute coordinates (absolute, regarding the screen of the device):

    MotionEvent.getRawX()

    MotionEvent.getRawY()

    The other methods, getX() and getY(), should return you coordinates relative to the View that dispatched them.