Summary1. I found that the Left, right, top, and bottom values of the view are different from those of the invalidate process. Now I want to analyze the specific meanings of these values. 2. Understand coordinates. The concept of position involves the concept of coordinate system. In a two-dimensional view, the coordinate system combines the X axis and Y axis to represent the absolute sit of a certain point.
1. Confused
During the invalidate process of the analysis view, we found that the Left, right, top, and bottom values of the view are different from those of the view. Now we want to analyze the specific meanings of these values.
2. Understand coordinates and positions
The concept of coordinate system is involved here:
In a two-dimensional view, the coordinate system combines the X axis and Y axis to represent the absolute coordinates of a certain point.
For example, (30,100) is usually a point that represents the intersection of the X axis 30 and the Y axis 100.
In Android, left can be equivalent to the x-axis value, and top is equivalent to the y-axis value. The Android system can use these two values to know the starting point of the view. In wdith and height, you can get the specific values of the top, bottom, and bottom views, you can draw a view at an absolute position on the screen. Right and bottom are calculated as follows:
Right = left + width;
Bottom = Top + height;
3. Corresponding APIs
View. getleft ()
View. getright ()
View. gettop ();
View. getbottom ();
View width view. getwidth ();
View height view. getheight ()
4. instance analysis
According to my understanding:
Left = 0 in the blue area, Top = 0 coordinates (0, 0)
Left = 60 in the yellow area, Top = 115 coordinates (60,115)
Green area location left = 115, Top = 170 coordinates (115,170)
The green area is incorrect. I think the position of the green area is for the (0, 0) coordinate value of the blue area, from the coordinate value printed in the lower right corner, we can see that it is inconsistent with the values listed below. Let's see the figure below.
Conclusion: The left, top, right, and bottom values of a view are for the relative position of its parent view, and the green area is for its parent view (that is, the yellow area is (0, 0) the coordinates should not be (115,170) But (55, 55)