
Ndroid There are two coordinate systems, respectively called Android coordinate system and the view coordinate system. The correspondence also some related methods can get coordinates coordinate system. Only clear these differences, in order not to error, or you can not get the desired effect at the time of implementation.
A, Android coordinate system and the view coordinate system
(1) Android coordinates
Let's take a look at Android coordinate system is what it looks like.
Android mobile phone screen coordinates of the top left vertex coordinate origin, from that point to the right of the xaxis positive direction, from that point down the yaxis positive direction. The touch event, use getRawX () and getRawY () method
Get the coordinates of this coordinate system is to coordinate values under the standard.
(2) the view coordinate system
android in another coordinate system called the view coordinate system, which describes the child views in the parent view location.
View coordinate system is the upper left corner of the parent view for the origin of coordinates. Corresponding to the origin of the right x axis positive direction, the positive yaxis origin for the downward direction. In touch by
Coordinate getX () and getY () to get the value is the coordinate values for the view coordinate system.
Second, the method of obtaining those coordinates as well as the relative distance
In the android, there is provided a very rich way to get coordinates and relative distance. However, when using these methods, which must be clear is to obtain the coordinates of the standard.
In order to clear them out of these methods
Description of each method for obtaining a coordinate value or distance is from where to where. Explain the figure there are three black frame, the outermost layer of the cell phone screen,
The intermediate layer is ViewGroup, the innermost is ViewGroup placed in view.
Methods annotated method can be divided into two categories, one is the View provided a method MotionEvent class is provided. Respectively, as follows:
Coordinate View provides access to and from the approach:
getTop () Gets the distance to the top edge of its parent layout view to its top edge
getLeft () to get a view of their own from the left to the left of its parent's layout
getRight () to get a view of their own to the right distance to the left of its parent's layout
getBottom () to get to the bottom of the view itself from the top edge of its parent's layout
MotionEvent method provided:
getX () Gets the distance from the controls on the left click event, that view coordinates
getY () Gets the distance from the event click on the top edge of the control that the view coordinates
getRawX () to get the click event is the distance from the entire screen to the left, that absolute coordinates
getRawY () to get the click event from the entire screen from the top edge of absolute coordinates 


