Android ViewGroup Usage Summary

Source: Internet
Author: User

ViewGroup definition

In the API is so descriptive of the narrative viewgroup: a viewgroup is a special view, can contain other views. According to the meaning we can be clear. Other UI controls can be included in ViewGroup. Including our own definition of the control

Advantages and Uses

We understand that the most important purpose of a UI control is to use it. And to understand the controls. The strength of the control must be clarified.

ViewGroup is relatively complex in Android UI controls, and its own definition is very high. By using Declare-styleable to define control properties, it is possible to control almost every convenience of a control.

With these strengths 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 an explanation of the two methods in the API. Both Onmeasure and onlayout can be called multiple times in real-world use. According to log we will find that onlayout are called after Onmeasure, which also confirms the API's argument, ViewGroup before drawing the value of the good, and then according to the corresponding values to draw the control to the corresponding place.

Getmeasuredwidth

This method is presented here alone for a moment. When the control is stored in the Onmeasure method. We will use Getmeasuredwidth () and Getmeasuredheight (), where the resulting value contains padding, does not include margin, and should be noted 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.