Onmeasure method of View

Source: Internet
Author: User
We know that the view displayed on the screen must first go through measure and layout. when calling the onmeasure (INT widthspec, int heightspec) method, it involves the use of measurespec. measurespec has three modes: unspecified, exactly, and at_most, so what is the relationship between these modes and the layout parameter fill_parent and wrap_content we usually set. After code testing, we know that when we set the width or height to fill_parent, the container calls the measure method of the sub-view during layout and the input mode is exactly, because the sub-view occupies the space of the remaining container, its size is determined. When wrap_content is set, the container transmits at_most,
Indicates the maximum size of a sub-view, so that the view will set its own size based on the upper limit. When the size of the sub-view is set to an exact value, the container imports exactly, while the unspecified mode of measurespec does not yet find the applicable conditions.

The onmeasure method of view defaults to the minimum size of mminwidth (usually 0) or background drawable when the mode is unspecified. When the mode is exactly or at_most, the size is set to the size of the input measurespec.

To correct this idea, the fill_parent should be a sub-view that will occupy the space of the remaining containers, rather than overwrite other view spaces that have already been laid out, of course, there is no space to allocate for the layout subview. Therefore, the fill_parent attribute is very important to the layout sequence. What I previously thought was to fill up all the container space. No wonder Google changed the fill_parent name to match_parent in version 2.2.

From -- http://blog.csdn.net/czh0766/article/details/5846460

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.