1 Arouse doubts
Analyze the view invalidate process to find the left of view, right, top, bottom and you understand the different, now want to analyze the meaning of these several values specific.
2 Understanding coordinates, position concept
This involves the concept of a coordinate system:
The coordinate system represents the absolute coordinates of a point in a two-dimensional view by combining the x-axis and the y-axis two digits. For example (30, 100) a point that usually represents the x-axis and the y-axis 100 crossing
In Android, you can put left equivalent to the x-axis value, top equivalent to the y-axis value, through the two values of the Android system can know the view of the drawing starting point, in the Wdith and Height can get the view up and down the specific value, you can on the screen absolute position drawing view. Right and bottom are calculated as follows:
right = left + width;
Bottom = top + height;
3 corresponding APIs
View left position View.getleft ()
View right position view.getright ()
The top position of the view view.gettop ();
View bottom position view.getbottom ();
View width view.getwidth ();
View Height view.getheight ()
4 Example Analysis
According to my understanding:
Blue Area Position left = 0, top = 0 coordinates (0, 0)
Yellow area Position left =, top = 115 coordinates (60, 115)
Green Zone Position left = 170 coordinates (115, 170)
Green area, here understand the error, I think the location of the green area is for the blue area of the (0, 0) coordinates of the value, from the lower right corner of the printed coordinate values can be seen with the below I listed the values are inconsistent, see the figure below to understand
Summary: The left, top, right, bottom values of the view are relative to their parent view, and the green area is for the coordinates of its parent view (that is, the yellow area is (0, 0) points) and should not be (115, 170) but (55, 55)
Android view coordinates getleft, getRight, GetTop, Getbottom