Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MotionEvent.getRawX and MotionEvent.getX

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?

like image 834
Laura Stone Avatar asked Dec 17 '13 14:12

Laura Stone


People also ask

What is the difference between getRawX () and getX ()?

java, getX() obtains the distance between the touch point and the left boundary of the View, and getRawX() obtains the absolute position x value of the touch point in the screen.

What is Action_up and Action_down?

Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN ). A pointer id remains valid until the pointer eventually goes up (indicated by ACTION_UP or ACTION_POINTER_UP ) or when the gesture is canceled (indicated by ACTION_CANCEL ).

What is motion event?

Motion events describe movements in terms of an action code and a set of axis values. The action code specifies the state change that occurred such as a pointer going down or up. The axis values describe the position and other movement properties.


2 Answers

Picture for easy understanding

=>

rawX = motionEvent.getX() + touchableButton.getX() + layout3.getX() + layout2.getX(); 
like image 28
Linh Avatar answered Nov 11 '22 06:11

Linh


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.

like image 103
Piyush Avatar answered Nov 11 '22 05:11

Piyush