Box: Layer & Overlap
Stack content with alignment control.
Box: Layer & Overlap is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Stacking on Top
When children should overlap rather than line up, you use a Box. It layers content on the same spot. 🗂️
Your First Box
A Box draws its children in order, each one on top of the previous. Later children sit above earlier ones, like stacked cards.
Box {
Image(painter, null)
Text("Caption")
}Z-Order Follows Source Order
The last child you write wins the top layer. So to put a label over a photo, place the Image first and the Text after it.
Box Sizes to Its Biggest Child
By default a Box wraps its largest child. The other children are positioned within that footprint instead of expanding it.
Aligning the Whole Box
The contentAlignment parameter sets a default spot for every child. Alignment.Center pulls them all to the middle of the Box.
Box(contentAlignment = Alignment.Center) {
Text("Centered")
}Aligning One Child
Inside a Box, each child can use the align modifier to override the default. This is how you pin one item to a corner.
Box {
Text("Top end", Modifier.align(Alignment.TopEnd))
}A Badge in the Corner
Overlap plus align gives you a classic badge: an avatar fills the Box while a small dot pins to the TopEnd corner.
Box {
Avatar()
Dot(Modifier.align(Alignment.TopEnd))
}Text Over an Image
A common pattern is a caption over a photo. Put the Image first, then align Text to BottomStart so it reads over the image.
Box {
Image(painter, null)
Text("Sunset", Modifier.align(Alignment.BottomStart))
}Filling and Backgrounds
Make a Box fill space with fillMaxSize, then add a background color. It becomes a handy layered container for a whole screen.
Box(Modifier.fillMaxSize().background(Color.Black)) {
Text("Hi")
}The Nine Alignment Spots
A Box offers nine alignment positions, from TopStart to BottomEnd, with Center in the middle. They cover every placement you need.
When to Reach for Box
Choose Box whenever pieces share the same area: overlays, badges, captions, or a spinner centered over content. It is your layering tool.
Quick Check
Let's confirm how a Box layers its children.
Recap: Box
You learned Box: it stacks children on the same spot in source order, sizes to its biggest child, and uses contentAlignment and align to place them.
Frequently asked questions
Is the “Box: Layer & Overlap” lesson free?
Yes — the full text of “Box: Layer & Overlap” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “Box: Layer & Overlap”?
Stack content with alignment control. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Box: Layer & Overlap” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.