🌈 Create new beautiful Compose Gradients with our new wesite ->
Compose Modifier

fillMaxWidth

Have the content fill (possibly only partially) the Constraints.maxWidth of the incoming measurement constraints, by setting the minimum width and the maximum width to be equal to the maximum width multiplied by fraction.

SimpleFillWidthModifier

@Sampled
@Composable
fun SimpleFillWidthModifier() {
    Box(Modifier.fillMaxWidth().background(Color.Red), contentAlignment = Alignment.Center) {
        Box(Modifier.size(100.dp).background(color = Color.Magenta))
    }
}

FillHalfWidthModifier

@Sampled
@Composable
fun FillHalfWidthModifier() {
    Box(Modifier.requiredSize(100.dp).background(Color.Red), contentAlignment = Alignment.Center) {
        // The inner Box will be (50.dp x 30.dp).
        Box(
            Modifier.fillMaxWidth(fraction = 0.5f)
                .requiredHeight(30.dp)
                .background(color = Color.Magenta)
        )
    }
}

Content updated: