requiredWidth
Common
Modifier in Compose Foundation Layout
Last updated:
Installation
dependencies {
implementation("androidx.compose.foundation:foundation-layout:1.8.0-alpha04")
}
Overloads
@Stable
fun Modifier.requiredWidth(intrinsicSize: IntrinsicSize)
@Stable
fun Modifier.requiredWidth(width: Dp)
Code Example
SimpleRequiredWidthModifier
@Composable
fun SimpleRequiredWidthModifier() {
// The result is a 50.dp x 50.dp magenta box centered in a 100.dp x 100.dp space.
// Note that although a previous modifier asked it to be 100.dp width, this
// will not be respected. They would be respected if width was used instead of requiredWidth.
Box(
Modifier.requiredWidth(100.dp)
.requiredWidth(50.dp)
.aspectRatio(1f)
.background(Color.Magenta)
)
}