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.