first clarify the coordinate system in Android: the upper-left corner of the screen is the coordinate system origin (0,0), the origin point extends to the right of the x-axis positive direction, the origin of the downward extension of the y-axis positive direction.
first, the coordinates of the view
It is important to note that the coordinates of the view are relative to the parent container, including: GetTop (), Getbottom (), GetLeft (), GetRight (). Take GetTop as an example, the function source code is:
/**
* Top position of this view relative to its parent.
* Relative to the top position of the parent control, in pixels, that is, the distance from the head to the parent control
* @return The top of this view, in pixels.
*/
@ViewDebug. Capturedviewproperty
Public final int getTop () {
return mtop;
}
Figure 1:
Figure 2:
1. Left position of view view.getleft ()
2. Right position of view view.getright ()
3, the top position of the view view.gettop ();
4, the view bottom position view.getbottom ();
5, view width view.getwidth ();
6. View Height view.getheight ()
Second, Motionevent class Getrowx () and GetX ()
1, Event.getrowx (): The x-coordinate of the touch point relative to the screen Origin
2, Event.getx (): The x-coordinate of the touch point relative to the origin of its component
Diagram
Android screen (View) coordinate system