Android GetWidth and Getmeasuredwidth

Source: Internet
Author: User

1. When a class is initialized, that is, in the constructor we are not getting the actual size of the view. Interested friends can try, getwidth () and getmeasuredwidth () results are all 0. But we can get the size of the control from inside the OnDraw () method.

2. The two results are measured in pixels, or pixel.

GetWidth (): Gets the width value of the view after it has been laid out in the parent layout, and if there is no parent, the default parent layout is the entire screen.

Getmeasuredwidth (): First look at what the API says.
The width of this view is measured in the most recent call to measure (). This should is used during measurement and layout calculations only.

The last call to the measure () method is the width of the view, which is used only in the calculation of measurement and layout. So this method gets the actual width that the view's content occupies.

Summary (positive solution):

GetWidth (): View the width of the entire view after setting the layout.

Getmeasuredwidth (): The width of the view content that is obtained when the content on the view is measured, if you must call measure (0,0) in the parent layout's OnLayout () method or in the OnDraw () method of this view;( You can define the values of the parameters in measure, otherwise you get the same results as the getwidth ().

Transferred from: http://blog.csdn.net/wangbofei/article/details/7795430

Android GetWidth and Getmeasuredwidth

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.