Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/view/View.MeasureSpec#constants) \| [Ctors](https://developer.android.com/reference/android/view/View.MeasureSpec#pubctors) \| [Methods](https://developer.android.com/reference/android/view/View.MeasureSpec#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/View.MeasureSpec#inhmethods)

# View.MeasureSpec

*** ** * ** ***


`
public
static


class
View.MeasureSpec
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.View.MeasureSpec |

<br />

*** ** * ** ***

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.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/View.MeasureSpec#AT_MOST` Measure specification mode: The child can be as large as it wants up to the specified size. |
| `int` | `https://developer.android.com/reference/android/view/View.MeasureSpec#EXACTLY` Measure specification mode: The parent has determined an exact size for the child. |
| `int` | `https://developer.android.com/reference/android/view/View.MeasureSpec#UNSPECIFIED` Measure specification mode: The parent has not imposed any constraint on the child. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/View.MeasureSpec#MeasureSpec()() ` |

| ### Public methods ||
|---|---|
| ` static int` | ` https://developer.android.com/reference/android/view/View.MeasureSpec#getMode(int)(int measureSpec) ` Extracts the mode from the supplied measure specification. |
| ` static int` | ` https://developer.android.com/reference/android/view/View.MeasureSpec#getSize(int)(int measureSpec) ` Extracts the size from the supplied measure specification. |
| ` static int` | ` https://developer.android.com/reference/android/view/View.MeasureSpec#makeMeasureSpec(int,%20int)(int size, int mode) ` Creates a measure specification based on the supplied size and mode. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/view/View.MeasureSpec#toString(int)(int measureSpec) ` Returns a String representation of the specified measure specification. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### AT_MOST

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AT_MOST
```

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

<br />

Constant Value:

-2147483648
(0x80000000)


### EXACTLY

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int EXACTLY
```

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.

<br />

Constant Value:

1073741824
(0x40000000)


### UNSPECIFIED

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int UNSPECIFIED
```

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

<br />

Constant Value:

0
(0x00000000)


## Public constructors

### MeasureSpec

```
public MeasureSpec ()
```

<br />

<br />

## Public methods

### getMode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getMode (int measureSpec)
```

Extracts the mode from the supplied measure specification.

<br />

| Parameters ||
|---|---|
| `measureSpec` | `int`: the measure specification to extract the mode from <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/View.MeasureSpec#UNSPECIFIED`, `https://developer.android.com/reference/android/view/View.MeasureSpec#AT_MOST` or `https://developer.android.com/reference/android/view/View.MeasureSpec#EXACTLY` Value is one of the following: - `https://developer.android.com/reference/android/view/View.MeasureSpec#UNSPECIFIED` - `https://developer.android.com/reference/android/view/View.MeasureSpec#EXACTLY` - `https://developer.android.com/reference/android/view/View.MeasureSpec#AT_MOST` |

### getSize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getSize (int measureSpec)
```

Extracts the size from the supplied measure specification.

<br />

| Parameters ||
|---|---|
| `measureSpec` | `int`: the measure specification to extract the size from <br /> |

| Returns ||
|---|---|
| `int` | the size in pixels defined in the supplied measure specification <br /> |

### makeMeasureSpec

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int makeMeasureSpec (int size, 
                int mode)
```

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

The mode must always be one of the following:

- `https://developer.android.com/reference/android/view/View.MeasureSpec#UNSPECIFIED`
- `https://developer.android.com/reference/android/view/View.MeasureSpec#EXACTLY`
- `https://developer.android.com/reference/android/view/View.MeasureSpec#AT_MOST`

**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.
`https://developer.android.com/reference/android/widget/RelativeLayout` was affected by this bug.
Apps targeting API levels greater than 17 will get the fixed, more strict
behavior.

<br />

<br />

| Parameters ||
|---|---|
| `size` | `int`: the size of the measure specification. Value is between 0 and 1073741823 inclusive <br /> |
| `mode` | `int`: the mode of the measure specification. Value is one of the following: - `https://developer.android.com/reference/android/view/View.MeasureSpec#UNSPECIFIED` - `https://developer.android.com/reference/android/view/View.MeasureSpec#EXACTLY` - `https://developer.android.com/reference/android/view/View.MeasureSpec#AT_MOST` |

| Returns ||
|---|---|
| `int` | the measure specification based on size and mode <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String toString (int measureSpec)
```

Returns a String representation of the specified measure
specification.

<br />

| Parameters ||
|---|---|
| `measureSpec` | `int`: the measure specification to convert to a String <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a String with the following format: "MeasureSpec: MODE SIZE" <br /> |