Difference between MotionEvent.getRawX and MotionEvent.getX

AndroidAndroid LayoutAndroid Ui

Android Problem Overview


I would like to know The difference between MotionEvent.getRawX and MotionEvent.getX in android as one is numeric and the other is float?Whats the need to have both of these types?

Android Solutions


Solution 1 - Android

MotionEvent will sometimes return absolute X and Y coordinates relative to the view, and sometimes relative coordinates to the previous motion event.

getRawX() and getRawY() that is guaranteed to return absolute coordinates, relative to the device screen.

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

Solution 2 - Android

Picture for easy understanding

=>

rawX = motionEvent.getX() + touchableButton.getX() + layout3.getX() + layout2.getX();

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaura StoneView Question on Stackoverflow
Solution 1 - AndroidPiyushView Answer on Stackoverflow
Solution 2 - AndroidLinhView Answer on Stackoverflow