New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation Layout

fillMaxSize

Common

Have the content fill (possibly only partially) the [Constraints.maxWidth] and [Constraints.maxHeight] of the incoming measurement constraints, by setting the [minimum width][Constraints.minWidth] and the [maximum width][Constraints.maxWidth] to be equal to the [maximum width][Constraints.maxWidth] multiplied by [fraction], as well as the [minimum height][Constraints.minHeight] and the [maximum height][Constraints.minHeight] to be equal to the [maximum height][Constraints.maxHeight] multiplied by [fraction]. Note that, by default, the [fraction] is 1, so the modifier will make the content fill the whole available space. If the incoming maximum width or height is [Constraints.Infinity] this modifier will have no effect in that dimension.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.7.0-beta04")
}

Overloads

@Stable
fun Modifier.fillMaxSize(@FloatRange(from = 0.0, to = 1.0) fraction: Float = 1f)

Parameters

namedescription
fractionThe fraction of the maximum size to use, between 0 and 1, inclusive.

Code Examples

SimpleFillModifier

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

FillHalfSizeModifier

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