Compose Modifier

layout

Creates a LayoutModifier that allows changing how the wrapped element is measured and laid out.

ConvenienceLayoutModifierSample

@Sampled
@Composable
fun ConvenienceLayoutModifierSample() {
    Box(
        Modifier.background(Color.Gray).layout { measurable, constraints ->
            // an example modifier that adds 50 pixels of vertical padding.
            val padding = 50
            val placeable = measurable.measure(constraints.offset(vertical = -padding))
            layout(placeable.width, placeable.height + padding) {
                placeable.placeRelative(0, padding)
            }
        }
    ) {
        Box(Modifier.fillMaxSize().background(Color.DarkGray))
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: