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