0Pricing
Jetpack Compose Academy · Lección

Un FlowRow que ajusta los chips

Cree desde cero un layout envolvente real.

Un FlowRow que ajusta los chips es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 4 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.

What a Flow Row Does

A flow row places children left to right, then wraps to a new line when it runs out of width. Perfect for tag chips and filters. 🏷️

Start From the Layout Composable

You already know the tool: the Layout composable. The wrapping logic lives entirely in how you measure and place children.

Layout(content, modifier) { measurables, constraints ->
}

Measure Children Loosely

Measure each chip with the parent's maxWidth but no minimum, so chips size to their content rather than stretching full width.

val placeables = measurables.map {
  it.measure(constraints.copy(minWidth = 0))
}

Track the Current Row Width

Walk the placeables and keep a running row width. Each chip you add increases it by the chip's own width.

Wrap When the Row Overflows

If adding the next chip would exceed maxWidth, reset the row width and move down by the tallest chip in the finished row.

if (rowWidth + placeable.width > maxWidth) {
  y += rowHeight
  rowWidth = 0
}

Remember Each Chip's Position

As you scan, store the chosen x and y for every chip in a list. You will replay these positions during the placement step.

Compute the Total Height

After the last row, the layout's height is the final y plus that row's height. The width is simply the constraint's maxWidth.

Report Size and Place Chips

Call layout with your total width and height, then loop through the stored positions, calling placeRelative on each placeable.

layout(maxWidth, totalHeight) {
  placeables.forEachIndexed { i, p ->
    p.placeRelative(positions[i])
  }
}

Add Horizontal Spacing

Insert a small gap between chips by adding a spacing value to the row width after each chip. Vertical gaps work the same way.

Compose Ships FlowRow Too

The official FlowRow from the layout library does all this for you. Building it yourself shows exactly how that magic works under the hood. ✨

FlowRow { Chip("Kotlin"); Chip("Compose") }

You Built a Real Layout

You measured children, wrapped rows by width, and placed each chip by hand. That is a production-grade custom layout built from first principles. 🎉

Quick Check

What triggers the flow row to start a new line?

Recap: A FlowRow That Wraps Chips

You measured chips loosely, tracked row width, and wrapped to a new line on overflow, then placed each one. That is FlowRow from scratch. ✅

Preguntas frecuentes

¿La lección «Un FlowRow que ajusta los chips» es gratis?

Sí — el texto completo de «Un FlowRow que ajusta los chips» 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 «Un FlowRow que ajusta los chips»?

Cree desde cero un layout envolvente real. 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 4 de 4.

¿Cuánto tiempo toma la lección «Un FlowRow que ajusta los chips»?

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

  1. El modelo de medir y colocar
  2. Escribir un Composable Layout
  3. Restricciones y medidas intrínsecas
  4. Un FlowRow que ajusta los chips
← Volver a Jetpack Compose Academy