← Back to Foundation Layout
wrapContentWidth
Modifier
in
Foundation Layout
. Since 0.1.0-dev15Overview
Examples
Community Notes
@Composable
fun SimpleWrapContentHorizontallyAlignedModifier() {
// Here the result will be a 20.dp x 50.dp blue box centered vertically in a 50.dp x 50.dp
// space. Because of the size modifier, if wrapContentWidth did not exist,
// the blue rectangle would actually be 50.dp x 50.dp to satisfy the size set by the modifier.
// However, because we provide wrapContentWidth, the blue rectangle is specified to be wrap
// content in width - if the desired width is smaller than 50.dp, it will be centered
// horizontally in this space. Therefore the 50.dp x 20.dp is centered horizontally
// in the space.
Box(
Modifier.size(50.dp)
.wrapContentWidth(Alignment.CenterHorizontally)
.width(20.dp)
.background(Color.Blue)
)
}
Next ComponentAlignmentLineOffset →