{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Measurable

public interface Measurable extends IntrinsicMeasurable


A part of the composition that can be measured. This represents a layout. The instance should never be stored.

Summary

Public methods

abstract @NonNull Placeable
measure(@NonNull Constraints constraints)

Measures the layout with constraints, returning a Placeable layout that has its new size.

Extension functions

default final Object

Retrieves the tag associated to a composable with the Modifier.layoutId modifier.

Inherited methods

From androidx.compose.ui.layout.IntrinsicMeasurable
abstract Object

Data provided by the ParentDataModifier.

abstract int
maxIntrinsicHeight(int width)

Calculates the smallest height beyond which increasing the height never decreases the width.

abstract int
maxIntrinsicWidth(int height)

Calculates the smallest width beyond which increasing the width never decreases the height.

abstract int
minIntrinsicHeight(int width)

Calculates the minimum height that the layout can be such that the content of the layout will be painted correctly.

abstract int
minIntrinsicWidth(int height)

Calculates the minimum width that the layout can be such that the content of the layout will be painted correctly.

Public methods

measure

abstract @NonNull Placeable measure(@NonNull Constraints constraints)

Measures the layout with constraints, returning a Placeable layout that has its new size. A Measurable can only be measured once inside a layout pass.

Extension functions

LayoutIdKt.getLayoutId

default final Object LayoutIdKt.getLayoutId(@NonNull Measurable receiver)

Retrieves the tag associated to a composable with the Modifier.layoutId modifier. For a parent data value to be returned by this property when not using the Modifier.layoutId modifier, the parent data value should implement the LayoutIdParentData interface.

Example usage:

import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.unit.Constraints

Layout({
    // Here the Containers are only needed to apply the modifiers. You could use the
    // modifier on header and footer directly if they are composables accepting modifiers.
    Box(Modifier.layoutId("header")) { header() }
    Box(Modifier.layoutId("footer")) { footer() }
}) { measurables, constraints ->
    val placeables = measurables.map { measurable ->
        when (measurable.layoutId) {
            // You should use appropriate constraints. Here we measure fake constraints.
            "header" -> measurable.measure(Constraints.fixed(100, 100))
            "footer" -> measurable.measure(constraints)
            else -> error("Unexpected tag")
        }
    }
    // Size should be derived from children measured sizes on placeables,
    // but this is simplified for the purposes of the example.
    layout(100, 100) {
        placeables.forEach { it.placeRelative(0, 0) }
    }
}