Build apps faster with our new App builder! Check it out →

Spacer

Common

Component in Compose Foundation Layout

Component that represents an empty space layout, whose size can be defined using [Modifier.width], [Modifier.height] and [Modifier.size] modifiers.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.8.0-alpha04")
}

Overloads

@Composable
@NonRestartableComposable
fun Spacer(modifier: Modifier)

Parameters

namedescription
modifiermodifiers to set to this spacer

Code Example

SpacerExample

@Composable
fun SpacerExample() {
    Row {
        Box(Modifier.size(100.dp).background(Color.Red))
        Spacer(Modifier.width(20.dp))
        Box(Modifier.size(100.dp).background(Color.Magenta))
        Spacer(Modifier.weight(1f))
        Box(Modifier.size(100.dp).background(Color.Black))
    }
}
by @alexstyl