New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation Layout

aspectRatio

Common

Last updated:

Installation

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

Overloads

@Stable
fun Modifier.aspectRatio(
    @FloatRange(from = 0.0, fromInclusive = false)
    ratio: Float,
    matchHeightConstraintsFirst: Boolean = false
)

Parameters

namedescription
ratiothe desired width/height positive ratio

Code Example

SimpleAspectRatio

@Composable
@Sampled
fun SimpleAspectRatio() {
    Box(Modifier.width(100.dp).aspectRatio(2f).background(Color.Green))
}