Android View coordinates getleft, getright, gettop, and getbottom

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.