Partager via


View.OnMeasure(Int32, Int32) Method

Definition

Measure the view and its content to determine the measured width and the measured height.

[Android.Runtime.Register("onMeasure", "(II)V", "GetOnMeasure_IIHandler")]
protected virtual void OnMeasure (int widthMeasureSpec, int heightMeasureSpec);
[<Android.Runtime.Register("onMeasure", "(II)V", "GetOnMeasure_IIHandler")>]
abstract member OnMeasure : int * int -> unit
override this.OnMeasure : int * int -> unit

Parameters

widthMeasureSpec
Int32

horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.

heightMeasureSpec
Int32

vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.

Attributes

Remarks

Measure the view and its content to determine the measured width and the measured height. This method is invoked by #measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

<strong>CONTRACT:</strong> When overriding this method, you <em>must</em> call #setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by #measure(int, int). Calling the superclass' #onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override #onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (#getSuggestedMinimumHeight() and #getSuggestedMinimumWidth()).

Java documentation for android.view.View.onMeasure(int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also