Box: superponer elementos
Apile contenido controlando su alineación.
Box: superponer elementos es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Jetpack Compose Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Jetpack Compose Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Box: superponer elementos» es gratis?
Sí — el texto completo de «Box: superponer elementos» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Jetpack Compose Academy, actualiza a CoddyKit PRO. El curso de Jetpack Compose Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Box: superponer elementos»?
Apile contenido controlando su alineación. Practicas Jetpack Compose Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Jetpack Compose Academy?
No se requiere experiencia previa. Jetpack Compose Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Box: superponer elementos»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Jetpack Compose Academy?
Sí. Cada lección de Jetpack Compose Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Column: apilar elementos verticalmente
- Row: colocar elementos uno junto a otro
- Box: superponer elementos
- Distribución y alineación