Android ViewGroup Usage Summary

Source: Internet
Author: User

ViewGroup definition

In the API, this describes ViewGroup: a viewgroup is a special view, can contain other views. By meaning we can understand that other UI controls, including our custom controls, can be included in ViewGroup

Advantages and Uses

We understand that the most important purpose of a UI control is to use it. To understand the control, you must understand the advantages of the control. ViewGroup is relatively complex in Android UI controls, it is highly customizable, and with Declare-styleable custom control properties, almost every convenience of a control can be controlled.

With these advantages in mind, where do you think you can find ViewGroup? Think about it and I'll talk about my understanding at the end of the article.

Drawing process

There are two and important callback methods in ViewGroup

    • onmeasure (int widthmeasurespec, int heightmeasurespec)
    • OnLayout (Boolean changed, int left, int top, int. right, int bottom)
Onmeasure

Ask all children to measure themselves and compute the measurement of this layout based on the children.

OnLayout

Position all children within this layout.

The above is the API in the interpretation of two methods, the real use of onmeasure and onlayout can be called multiple times, according to log we will find that onlayout are not called after Onmeasure, which confirms the API's statement, ViewGroup the numerical value before drawing, and then draws the control to the corresponding place according to the corresponding value.

Getmeasuredwidth

This method here alone to say, in the Onmeasure method to calculate the location of the control, we will use the Getmeasuredwidth () and Getmeasuredheight (), the resulting values include padding, not including margin, Be careful when calculating.

Android ViewGroup Usage Summary

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.