Bird
Raised Fist0
Android Kotlinmobile~20 mins

Spacer composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of the Spacer composable in Jetpack Compose?
easy
A. To display an image
B. To create buttons
C. To handle user input
D. To add empty space between UI elements

Solution

  1. Step 1: Understand Spacer's role

    The Spacer composable is designed to add empty space in layouts.
  2. Step 2: Compare with other UI elements

    Unlike buttons or images, Spacer does not display content but creates gaps.
  3. Final Answer:

    To add empty space between UI elements -> Option D
  4. Quick Check:

    Spacer = empty space [OK]
Hint: Spacer creates gaps, not visible content [OK]
Common Mistakes:
  • Thinking Spacer displays content
  • Confusing Spacer with Button or Image
  • Using Spacer to handle clicks
2. Which of the following is the correct way to create a Spacer with a height of 16.dp in Jetpack Compose?
easy
A. Spacer(modifier = Modifier.height(16.dp))
B. Spacer(height = 16.dp)
C. Spacer(size = 16.dp)
D. Spacer(width = 16.dp)

Solution

  1. Step 1: Check Spacer syntax

    Spacer requires a Modifier to set size properties like height or width.
  2. Step 2: Identify correct Modifier usage

    Using Modifier.height(16.dp) correctly sets the height of the Spacer.
  3. Final Answer:

    Spacer(modifier = Modifier.height(16.dp)) -> Option A
  4. Quick Check:

    Modifier.height sets Spacer height [OK]
Hint: Use Modifier.height() or Modifier.width() with Spacer [OK]
Common Mistakes:
  • Passing height directly as parameter
  • Using size instead of modifier
  • Confusing width and height properties
3. What will be the visual result of this code snippet?
Row {
  Text("Hello")
  Spacer(modifier = Modifier.width(24.dp))
  Text("World")
}
medium
A. The texts "Hello" and "World" will be close together with no space
B. There will be a 24.dp horizontal space between "Hello" and "World"
C. The texts will be stacked vertically
D. The Spacer will cause a runtime error

Solution

  1. Step 1: Understand Row layout

    Row arranges children horizontally in a line.
  2. Step 2: Analyze Spacer usage

    Spacer with Modifier.width(24.dp) adds 24.dp horizontal empty space between the two Text composables.
  3. Final Answer:

    There will be a 24.dp horizontal space between "Hello" and "World" -> Option B
  4. Quick Check:

    Spacer width adds horizontal gap [OK]
Hint: Spacer width in Row adds horizontal space [OK]
Common Mistakes:
  • Thinking Spacer stacks vertically in Row
  • Expecting no space between texts
  • Assuming Spacer causes error
4. Identify the error in this code snippet:
Column {
  Text("Top")
  Spacer(Modifier.size(20.dp))
  Text("Bottom")
}
medium
A. There is no syntax error; the code runs correctly
B. Spacer cannot be used inside Column
C. Spacer requires named parameter 'modifier = ' before Modifier.size()
D. Text composables must be wrapped in Box

Solution

  1. Step 1: Check Spacer syntax

    Spacer accepts a single positional Modifier parameter, so Spacer(Modifier.size(20.dp)) is syntactically correct.
  2. Step 2: Validate Modifier and layout

    Modifier.size(20.dp) is valid and Spacer works inside Column to occupy vertical space.
  3. Final Answer:

    There is no syntax error; the code runs correctly -> Option A
  4. Quick Check:

    Spacer(Modifier.size()) valid syntax [OK]
Hint: Spacer accepts positional Modifier argument [OK]
Common Mistakes:
  • Thinking named 'modifier =' is required
  • Believing Spacer disallowed in Column
  • Misunderstanding Modifier.size()
5. You want to create a vertical layout with two buttons separated by flexible space that pushes the second button to the bottom of the screen. Which Spacer usage achieves this?
hard
A. Row(Modifier.fillMaxSize()) { Button(onClick = {}) { Text("Top") } Spacer(modifier = Modifier.weight(1f)) Button(onClick = {}) { Text("Bottom") } }
B. Column(Modifier.fillMaxSize()) { Button(onClick = {}) { Text("Top") } Spacer(modifier = Modifier.height(50.dp)) Button(onClick = {}) { Text("Bottom") } }
C. Column(Modifier.fillMaxSize()) { Button(onClick = {}) { Text("Top") } Spacer(modifier = Modifier.weight(1f)) Button(onClick = {}) { Text("Bottom") } }
D. Column(Modifier.fillMaxSize()) { Button(onClick = {}) { Text("Top") } Spacer(modifier = Modifier.width(100.dp)) Button(onClick = {}) { Text("Bottom") } }

Solution

  1. Step 1: Understand layout direction

    Column arranges children vertically, so vertical spacing is needed.
  2. Step 2: Use Spacer with weight for flexible space

    Modifier.weight(1f) makes Spacer fill remaining space, pushing the bottom button down.
  3. Step 3: Eliminate incorrect options

    Fixed height or width spacers do not push content flexibly; Row arranges horizontally, not vertically.
  4. Final Answer:

    Column(Modifier.fillMaxSize()) { Button(onClick = {}) { Text("Top") } Spacer(modifier = Modifier.weight(1f)) Button(onClick = {}) { Text("Bottom") } } -> Option C
  5. Quick Check:

    Spacer with weight fills flexible space [OK]
Hint: Use Modifier.weight(1f) in Column for flexible vertical space [OK]
Common Mistakes:
  • Using fixed height instead of weight
  • Using Row instead of Column
  • Using width modifier in vertical layout
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard