The View System Android (III): and a method described coordinate View

In the actual development, we will always be dealing with and View, for example View slide, obtaining View coordinates, etc., it will involve many Api method provided by the system, so today, we take a closer look, relating to the system method.

A. Coordinate System

First, we first need to look inside Android coordinate system (two-dimensional coordinate system). There are two coordinate systems in Android, Android coordinate system (screen coordinate system) and the view coordinate system (coordinate system View). First on a map, as follows:
Here Insert Picture Description
by the above picture, we can see that:

1.Android coordinate system, based on the phone screen upper left corner as the origin , the horizontal rightward direction is the positive X-axis, a vertical y-axis positive direction is downward;

2. the view coordinate system, the origin is the parent View View of the upper left corner, the horizontal rightward direction is the positive X-axis, a vertical y-axis positive direction is downward;

Need to add that, ** View view can be no borders, in other words, the size of the View view may be larger than the Android phone screen, and even much larger. Or still on the drawing instructions, ** as follows:
Here Insert Picture Description
this figure, the black frame is the size of View, yellow frame is the size of the phone screen, we can see that the size of the View bigger than the phone screen, and only phone screen inside, we can see. Currently the phone screen displays only Buttton2 button, not yellow wireframe view, is hidden (not visible) state, when we slide your finger around on the phone screen, other hidden views may only be displayed. So, we may encounter in the layout, some only a portion of View, this is why!

Api Method Two explanations provided .Android

Method commonly used to 1.View.

(1) getLeft (), from the left edge of the current View View parent and its left edge (the view coordinates);

(2) getRight (), from the right edge of the current View View parent and its left edge (the view coordinates);

(3) getTop (), and the distance of its parent View upper edge (top) of the upper edge of the current View (view coordinates);

(4) getBottom (), with its current parent View, from the upper edge (top) of the lower edge of View (the view coordinates);

(5) getWidth (), get the current width of View;

(6) getHeight (), to get the current View height;

Look at a map, we might glance up.
Here Insert Picture Description
There are several commonly used in 2.MotionEvent method getX (), getY (), getRawX (), getRawY (). (This is the MotionEvent View, onTouchEvent (method)) of

(1) getX (), from the center point of the left edge of the touch of the View (view coordinates);

(2) getY (), the center point of the touch distance from the edge (top) of the View (view coordinates);

(3) getRawX (), distance from the center point of the left edge of the touch screen (absolute coordinates);

(4) getRawY (), from the edge (top) and the center point on a touch screen (absolute coordinates);

Please note that these are the methods MotionEvent, when called MotionEvent.getX () .... Look at a map, as follows:
Here Insert Picture Description

III. Summary

Android system is the core of View programming interface, it's as important as the four major components of Android, View of trying to coordinate summarized as follows:
Here Insert Picture Description

Published 81 original articles · won praise 37 · views 50000 +

Guess you like

Origin blog.csdn.net/gaolh89/article/details/104065520