Android view coordinates getleft, getRight, GetTop, Getbottom

Source: Internet
Author: User

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

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.