0
0
Android Kotlinmobile~20 mins

Spacer composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spacer Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Spacer composable behavior in a Row
What will be the visual result of this code snippet in a Row layout?
Row {
  Text("Start")
  Spacer(modifier = Modifier.width(16.dp))
  Text("End")
}
Android Kotlin
Row {
  Text("Start")
  Spacer(modifier = Modifier.width(16.dp))
  Text("End")
}
ATwo texts with 16.dp space between them horizontally
BTwo texts stacked vertically with 16.dp space
CTexts overlap with no space between
DOnly the first text is visible
Attempts:
2 left
💡 Hint
Remember Spacer adds empty space in the direction of the layout.
ui_behavior
intermediate
2:00remaining
Spacer usage in Column with height modifier
What happens when you use Spacer with Modifier.height(24.dp) inside a Column?
Column {
  Text("Top")
  Spacer(modifier = Modifier.height(24.dp))
  Text("Bottom")
}
Android Kotlin
Column {
  Text("Top")
  Spacer(modifier = Modifier.height(24.dp))
  Text("Bottom")
}
ANo space is added, texts are adjacent
BSpacer causes a crash due to missing width
CAdds horizontal space of 24.dp between the two Text composables
DAdds vertical space of 24.dp between the two Text composables
Attempts:
2 left
💡 Hint
Column arranges children vertically; height modifier affects vertical space.
lifecycle
advanced
2:00remaining
Spacer composable with fillMaxSize modifier
What is the effect of using Spacer with Modifier.fillMaxSize() inside a Box?
Box(modifier = Modifier.size(100.dp)) {
  Spacer(modifier = Modifier.fillMaxSize())
  Text("Hello")
}
Android Kotlin
Box(modifier = Modifier.size(100.dp)) {
  Spacer(modifier = Modifier.fillMaxSize())
  Text("Hello")
}
ASpacer pushes Text outside the Box bounds
BSpacer is invisible and does not affect layout
CSpacer fills the entire Box, Text is drawn on top
DApp crashes due to conflicting modifiers
Attempts:
2 left
💡 Hint
fillMaxSize makes Spacer fill all available space inside its parent.
📝 Syntax
advanced
2:00remaining
Correct syntax for Spacer with padding and size
Which option correctly creates a Spacer with 8.dp padding and 40.dp width and height?
ASpacer(modifier = Modifier.padding(8.dp).size(40.dp))
BSpacer(modifier = Modifier.size(40.dp).padding(8.dp))
CSpacer(modifier = Modifier.size(40.dp, 40.dp).padding(8.dp))
DSpacer(modifier = Modifier.padding(8).size(40))
Attempts:
2 left
💡 Hint
Use dp units and chain modifiers correctly.
🔧 Debug
expert
2:00remaining
Why does this Spacer not add space in a Row?
Given this code, why is there no visible space between the Text composables?
Row {
  Text("Left")
  Spacer(modifier = Modifier.height(16.dp))
  Text("Right")
}
Android Kotlin
Row {
  Text("Left")
  Spacer(modifier = Modifier.height(16.dp))
  Text("Right")
}
ASpacer requires a weight modifier to add space
BSpacer uses height modifier in a horizontal Row, so no horizontal space is added
CText composables ignore Spacer by default
DSpacer must be placed outside the Row to work
Attempts:
2 left
💡 Hint
Consider the layout direction and which dimension the Spacer affects.