Padding, tamaño y fillMaxWidth
Controle el espacio dentro y alrededor de un Composable.
Padding, tamaño y fillMaxWidth es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 1 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.
Meet the Modifier
A Modifier is how you adjust a Composable: its size, spacing, and decoration. You chain calls onto it, one tweak at a time. 🧩
Pass It In
Almost every Composable takes a modifier parameter. You pass it as the first thing to change about that element.
Text(
text = "Hi",
modifier = Modifier
)Add Some Padding
Use padding to add empty space around a Composable. It pushes everything else away, giving your element room to breathe.
Text(
"Hi",
modifier = Modifier.padding(16.dp)
)The dp Unit
Sizes use dp, density-independent pixels. They look the same on every screen, so 16.dp is consistent across phones and tablets.
Padding Per Side
You can pad each side differently. Pass horizontal and vertical, or name individual sides like start and top.
Modifier.padding(
horizontal = 16.dp,
vertical = 8.dp
)Set a Fixed Size
Use size to give a Composable an exact width and height. One value makes it square; two values set each dimension.
Modifier.size(width = 120.dp, height = 48.dp)Width and Height Alone
Need only one dimension? Use width or height on their own and let the other side wrap its content naturally.
Modifier.height(56.dp)Fill the Width
fillMaxWidth stretches a Composable to take up all the horizontal space its parent offers. Great for full-width buttons and rows.
Modifier.fillMaxWidth()Fill a Fraction
Pass a fraction to fill only part of the space. fillMaxWidth(0.5f) takes half the available width instead of all of it.
Modifier.fillMaxWidth(0.5f)Fill Everything
Use fillMaxSize to expand in both directions at once. It is the shortcut for filling width and height together.
Modifier.fillMaxSize()Chain Them Together
The real power is chaining: stack padding, size, and fill in one fluent call to shape an element exactly how you want.
Modifier
.fillMaxWidth()
.padding(16.dp)Quick Check
Which modifier stretches a Composable across all the horizontal space its parent gives?
Recap
You learned to space, size, and stretch any Composable. padding adds room, size sets exact bounds, and fillMaxWidth grows to fit. ✨
Preguntas frecuentes
¿La lección «Padding, tamaño y fillMaxWidth» es gratis?
Sí — el texto completo de «Padding, tamaño y fillMaxWidth» 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 «Padding, tamaño y fillMaxWidth»?
Controle el espacio dentro y alrededor de un Composable. 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 1 de 4.
¿Cuánto tiempo toma la lección «Padding, tamaño y fillMaxWidth»?
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
- Padding, tamaño y fillMaxWidth
- Fondo, borde y clip
- Por qué importa el orden de los modificadores
- weight y tamaños flexibles