Measurement of Android View

Source: Internet
Author: User

First, Introduction

The Android system must measure the view before drawing the view, which tells the system how much view to draw. This process is performed in the Onmeasure () method. The Android system provides the Measurespec class by helping us measure the view.

The measurement mode can be divided into three types:

    • Exactly: that is the exact value mode, the system uses the exactly mode by default.
    • At_most: The maximum mode, when the control's Layout_width property or Layout_height property is specified as Wrap_content, the size of the control generally varies with the control's sub-space or content. The size of this control can be as long as it does not exceed the maximum size allowed by the parent control.
    • UNSPECIFIED: It does not specify its size measurement mode, how large the view is, and is normally used when drawing a custom view.

The default Onmeasure () method of the view class supports only exactly mode, so you can only use exactly mode when customizing the control without overriding the Onmeasure () method.

With the Measurespec class, you can get the measurement mode of the view and the size that the view wants to draw. With this information, you can control the size of the view's last display.

Second, examples
1 @Override 2 protected void onmeasure (intint  heightmeasurespec)3{4     Super. Onmeasure (Widthmeasurespec, heightmeasurespec); 5 }

Measurement of Android View

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.