Measure Method of View, viewmeasure Method

Source: Internet
Author: User

Measure Method of View, viewmeasure Method

Public final void measure (int widthMeasureSpec, int heightMeasureSpec) Added in API level 1

This is called to find out how big a view shocould be. The parent supplies constraint information in the width and height parameters.

The actual measurement work of a view is saved med inonMeasure(int, int), Called by this method. Therefore, onlyonMeasure(int, int)Can and must be overridden by subclasses.

Parameters
WidthMeasureSpec Horizontal space requirements as imposed by the parent
HeightMeasureSpec Vertical space requirements as imposed by the parent

This method is called to calculate the size of the view. The parent view of the view provides constraints on the width and height. The actual measurement of view is performed in onMeasure of the method call. Only onMeasure can and must be overloaded by the view subclass to achieve more efficient and accurate measurement processes.


Parameters:

WidthMeasureSpec The requirements of the horizontal space imposed by the parent view can be understood as the width measurement specification.

HeightMeasureSpec the Needs of the portrait space imposed by the parent view, which can be understood as the height measurement specification.


The measurement specification is the Space Constraint added by the parent view, because the size of a view can be set to the size of the parent view and the size of other sibling views, such as match_parent. Therefore, when calculating the actual size of a view, you must consider the constraints of the parent view.


In general, the measure method of view is provided to the view system.Calculate the actual size of a view based on the parent view constraint.. The measure method cannot be overloaded because the android view system uses this method to implement the view system function. To customize a view size calculation process, you can only reload the onMeasure method.


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.