# MeasurePolicy

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+class:androidx.compose.ui.layout.MeasurePolicy) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  fun interface MeasurePolicy
  ```

*** ** * ** ***

Defines the measure and layout behavior of a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)`. `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy` are the way Compose layouts (such as `Box`, `Column`, etc.) are built, and they can also be used to achieve custom layouts.

See `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` samples for examples of how to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy`.

Intrinsic measurement methods define the intrinsic size of the layout. These can be queried by the layout's parent in order to obtain, in specific cases, more information about the size of the layout in the absence of specific constraints:

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicWidth(kotlin.collections.List,kotlin.Int)` defines the minimum width this layout can take, given a specific height, such that the content of the layout will be painted correctly

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicHeight(kotlin.collections.List,kotlin.Int)` defines the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicWidth(kotlin.collections.List,kotlin.Int)` defines the minimum width such that increasing it further will not decrease the minimum intrinsic height

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicHeight(kotlin.collections.List,kotlin.Int)` defines the minimum height such that increasing it further will not decrease the minimum intrinsic width

Most layout scenarios do not require querying intrinsic measurements. Therefore, when writing a custom layout, it is common to only define the actual measurement, as most of the times the intrinsic measurements of the layout will not be queried. Moreover, intrinsic measurement methods have default implementations that make a best effort attempt to calculate the intrinsic measurements by reusing the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.MeasureScope).measure(kotlin.collections.List,androidx.compose.ui.unit.Constraints)` method. Note this will not be correct for all layouts, but can be a convenient approximation.

Intrinsic measurements can be useful when the layout system enforcement of no more than one measurement per child is limiting. Layouts that use them are the `preferredWidth(IntrinsicSize)` and `preferredHeight(IntrinsicSize)` modifiers. See their samples for when they can be useful.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` |   |

## Summary

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicHeight(kotlin.collections.List,kotlin.Int)( measurables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable>, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicHeight(kotlin.Int)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicWidth(kotlin.collections.List,kotlin.Int)( measurables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable>, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicWidth(kotlin.Int)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.MeasureScope).measure(kotlin.collections.List,androidx.compose.ui.unit.Constraints)( measurables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Measurable>, constraints: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Constraints )` The function that defines the measurement and layout. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicHeight(kotlin.collections.List,kotlin.Int)( measurables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable>, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicHeight(kotlin.Int)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicWidth(kotlin.collections.List,kotlin.Int)( measurables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable>, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicWidth(kotlin.Int)`. | Cmn |

## Public functions

### IntrinsicMeasureScope.maxIntrinsicHeight

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+function:maxIntrinsicHeight)

```
open fun IntrinsicMeasureScope.maxIntrinsicHeight(
    measurables: List<IntrinsicMeasurable>,
    width: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicHeight(kotlin.Int)`. It represents the minimum height such that increasing it further will not decrease the minimum intrinsic width. There should be no side-effects from implementers of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicHeight(kotlin.collections.List,kotlin.Int)`.

### IntrinsicMeasureScope.maxIntrinsicWidth

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+function:maxIntrinsicWidth)

```
open fun IntrinsicMeasureScope.maxIntrinsicWidth(
    measurables: List<IntrinsicMeasurable>,
    height: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicWidth(kotlin.Int)`. It represents the minimum width such that increasing it further will not decrease the minimum intrinsic height. There should be no side-effects from implementers of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicWidth(kotlin.collections.List,kotlin.Int)`.

### MeasureScope.measure

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+function:measure) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun MeasureScope.measure(
    measurables: List<Measurable>,
    constraints: Constraints
): MeasureResult
```

The function that defines the measurement and layout. Each `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Measurable` in the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.MeasureScope).measure(kotlin.collections.List,androidx.compose.ui.unit.Constraints)` list corresponds to a layout child of the layout, and children can be measured using the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Measurable#measure(androidx.compose.ui.unit.Constraints)` method. This method takes the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Constraints` which the child should respect; different children can be measured with different constraints.

Measuring a child returns a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable`, which reveals the size chosen by the child as a result of its own measurement. According to the children sizes, the parent defines the position of the children, by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable.PlacementScope#(androidx.compose.ui.layout.Placeable).place(kotlin.Int,kotlin.Int,kotlin.Float)` the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable`s in the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult#placeChildren()` of the returned `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult`. Therefore the parent needs to measure its children with appropriate `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Constraints`, such that whatever valid sizes children choose, they can be laid out correctly according to the parent's layout algorithm. This is because there is no measurement negotiation between the parent and children: once a child chooses its size, the parent needs to handle it correctly.

Note that a child is allowed to choose a size that does not satisfy its constraints. However, when this happens, the placeable's `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#width()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#height()` will not represent the real size of the child, but rather the size coerced in the child's constraints. Therefore, it is common for parents to assume in their layout algorithm that its children will always respect the constraints. When this does not happen in reality, the position assigned to the child will be automatically offset to be centered on the space assigned by the parent under the assumption that constraints were respected. Rarely, when a parent really needs to know the true size of the child, they can read this from the placeable's `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#measuredWidth()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#measuredHeight()`.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult` objects are usually created using the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope#layout(kotlin.Int,kotlin.Int,kotlin.collections.Map,kotlin.Function1)` factory, which takes the calculated size of this layout, its alignment lines, and a block defining the positioning of the children layouts.

### IntrinsicMeasureScope.minIntrinsicHeight

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+function:minIntrinsicHeight)

```
open fun IntrinsicMeasureScope.minIntrinsicHeight(
    measurables: List<IntrinsicMeasurable>,
    width: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicHeight(kotlin.Int)`. It represents the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly. There should be no side-effect from implementers of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicHeight(kotlin.collections.List,kotlin.Int)`.

### IntrinsicMeasureScope.minIntrinsicWidth

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/MeasurePolicy.kt+function:minIntrinsicWidth)

```
open fun IntrinsicMeasureScope.minIntrinsicWidth(
    measurables: List<IntrinsicMeasurable>,
    height: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicWidth(kotlin.Int)`. It represents the minimum width this layout can take, given a specific height, such that the content of the layout can be painted correctly. There should be no side-effect from implementers of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicWidth(kotlin.collections.List,kotlin.Int)`.