Obtain the widget layout and screen position

Source: Internet
Author: User

In a layout, there is a control view v.
You can obtain its position in the layout by using the following methods:
V. getleft ();
V. getright ();
V. getbottom ();
V. gettop ();

 

In this way, we can obtain the position of the control's top, bottom, left, and right, relative to the parent, that is, its top, bottom, and left are several pixels away from the parent.
However, note: getleft () indicates the distance between the left side and the left side of the parent.
Note: getright () indicates the distance between the right side and the left side of the parent.
However, please note: gettop () indicates the distance between the top and the top of the parent.
Note: getbottom () indicates the distance between the lower part and the upper part of the parent.

Likewise, the same is true for parameters in the V. layout (L, t, R, B) method.

 
Use the following method to obtain the position of a widget on the screen:
Int v_location [] = new int [2];
V. getlocationonscreen (v_location );
Int step_ball_location_0 = v_location [0];
Int step_ball_location_1 = v_location [1];
Step_ball_location_0 and step_ball_location_1 are positions.
Note: it cannot be executed in the oncreate () method !!!! In this case, step_ball_location_0 and step_ball_location_1 are both 0.

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.