Where to get view in Android app

Source: Internet
Author: User

Gets the location of the view class interface control to help you add a new control.


Gets the relative coordinate position in the parent
This is relatively simple, needless to say, directly call the method of view: GetLeft, GetTop, Getbottom, GetRight obtained.

Get the absolute position in the screen

Getlocalvisiblerect


Getglobalvisiblerect

The method is to construct a rect to "set" the view. The coordinates of this rect are relative to the current activity.

For normal activity, the top of the rect is the visible status bar height + the distance from the upper left corner to the bottom of the title bar of the visible title bar height +rect.

For dialog-style activity, the y-coordinate is the top of the rect that is visible, the distance from the upper-left corner to the bottom of the title bar for the +rect height of the title bar.

At this point there is no disregard for the status bar.

Getlocationinwindow

This method stores the upper-left coordinate of the view in an array. This coordinate is relative to the current activity.

For normal activity, the y-coordinate is the visible status bar height + visible title bar height +view the upper-left corner to the bottom of the title bar.

In the case of hidden status bar/title bar, their height is calculated at 0.

For dialog-style activity, the y-coordinate is the distance from the visible title bar height +view to the bottom of the title bar.

At this point there is no disregard for the status bar.

Getlocationonscreen
This method is similar to the above, and it also stores the upper-left corner of the view in the array. But this coordinate is relative to the entire screen.
The y-coordinate is the distance from the upper-left corner of the view to the top of the screen.

Where to get view in Android app

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.