Added in API level 1

MeasureSpec


open class MeasureSpec
kotlin.Any
   ↳ android.view.View.MeasureSpec

A MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirement for either the width or the height. A MeasureSpec is comprised of a size and a mode. There are three possible modes:

UNSPECIFIED
The parent has not imposed any constraint on the child. It can be whatever size it wants.
EXACTLY
The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.
AT_MOST
The child can be as large as it wants up to the specified size.
MeasureSpecs are implemented as ints to reduce object allocation. This class is provided to pack and unpack the <size, mode> tuple into the int.

Summary

Constants
static Int

Measure specification mode: The child can be as large as it wants up to the specified size.

static Int

Measure specification mode: The parent has determined an exact size for the child.

static Int

Measure specification mode: The parent has not imposed any constraint on the child.

Public constructors

Public methods
open static Int
getMode(measureSpec: Int)

Extracts the mode from the supplied measure specification.

open static Int
getSize(measureSpec: Int)

Extracts the size from the supplied measure specification.

open static Int
makeMeasureSpec(size: Int, mode: Int)

Creates a measure specification based on the supplied size and mode.

open static String!
toString(measureSpec: Int)

Returns a String representation of the specified measure specification.

Constants

AT_MOST

Added in API level 1
static val AT_MOST: Int

Measure specification mode: The child can be as large as it wants up to the specified size.

Value: -2147483648

EXACTLY

Added in API level 1
static val EXACTLY: Int

Measure specification mode: The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.

Value: 1073741824

UNSPECIFIED

Added in API level 1
static val UNSPECIFIED: Int

Measure specification mode: The parent has not imposed any constraint on the child. It can be whatever size it wants.

Value: 0

Public constructors

MeasureSpec

MeasureSpec()

Public methods

getMode

Added in API level 1
open static fun getMode(measureSpec: Int): Int

Extracts the mode from the supplied measure specification.

Parameters
measureSpec Int: the measure specification to extract the mode from
Return
Int android.view.View.MeasureSpec#UNSPECIFIED, android.view.View.MeasureSpec#AT_MOST or android.view.View.MeasureSpec#EXACTLY Value is android.view.View.MeasureSpec#UNSPECIFIED, android.view.View.MeasureSpec#EXACTLY, or android.view.View.MeasureSpec#AT_MOST

getSize

Added in API level 1
open static fun getSize(measureSpec: Int): Int

Extracts the size from the supplied measure specification.

Parameters
measureSpec Int: the measure specification to extract the size from
Return
Int the size in pixels defined in the supplied measure specification

makeMeasureSpec

Added in API level 1
open static fun makeMeasureSpec(
    size: Int,
    mode: Int
): Int

Creates a measure specification based on the supplied size and mode. The mode must always be one of the following:

Note: On API level 17 and lower, makeMeasureSpec's implementation was such that the order of arguments did not matter and overflow in either value could impact the resulting MeasureSpec. android.widget.RelativeLayout was affected by this bug. Apps targeting API levels greater than 17 will get the fixed, more strict behavior.

Parameters
size Int: the size of the measure specification Value is between 0 and (1 << MeasureSpec.MODE_SHIFT) - 1 inclusive
mode Int: the mode of the measure specification Value is android.view.View.MeasureSpec#UNSPECIFIED, android.view.View.MeasureSpec#EXACTLY, or android.view.View.MeasureSpec#AT_MOST
Return
Int the measure specification based on size and mode

toString

Added in API level 1
open static fun toString(measureSpec: Int): String!

Returns a String representation of the specified measure specification.

Parameters
measureSpec Int: the measure specification to convert to a String
Return
String! a String with the following format: "MeasureSpec: MODE SIZE"