android--Custom ViewGroup ()

Source: Internet
Author: User

The essence of measure is to translate the relative values of the attempted layout into concrete values.
The Measurespec class wraps the layout requirements passed down from the parent, and each measurespec represents a requirement for width and height.

Why does a layout require a parent view and a child view to decide together?  Why not set width and height directly? If this is not the case, specify a fixed size like HTML, which will cause one to go through a lot of other extrusion.  Because HTML is control over the entire page. While Android is split, this ensures that the end-of-the-line (interface development) affects the layout of the other tiers and needs to follow (control development) rules. View.setwidth, View.setheight? No
Need to pass Measurechilde (view, width, height), or childview.measure ();

View.getwidth (), View.gethight ()
View.getmeasurewidth (), View.getmeasurehiegh ()
One that was not added to the view? But sometimes the getmesureheight still returns 0. Why? The EC is an internal class of Android.view.View that encapsulates the layout requirements information that is passed from the parent class to the subclass.

Measure methods provided by ViewGroup

Measurechildren ()-The function uses a for () Loop call Measurechild () to measure each sub-view measurechild ()- Measure operation for each sub-view measurechildwidthmargins ()-The only difference between this function and measurechild is that measure consider margin and padding as part of the child view size

There is a convention: When you overwrite the Onmeasure method, you must call Setmeasureddimension (Int,int) to store The view's measured measured width and height. If this is not done. A illegalstateexception will be thrown by the measure (int, int) method.

Measure (int widthmeasurespec, int heightmeasurespec), since the picture is square, the width and height values are the same.

When covering the Onmeasure method, the subclass is responsible for ensuring that the measured height width is at least the minimum height and width of the view.

Setmeasureddimension (Reswidth, resheight);

Gets the minimum available value for this control, if Android:minwidth is set, based on the size of the diagram you set.

If there is no background map, then the default size, the default is the screen width and high school small value

android--Custom ViewGroup ()

Related Article

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.