0Pricing
Jetpack Compose Academy · Lezione

Una FlowRow che va a capo

Costruisca da zero un vero layout a capo.

Una FlowRow che va a capo è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Jetpack Compose Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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. ✅

Domande Frequenti

La lezione «Una FlowRow che va a capo» è gratuita?

Sì — il testo completo di «Una FlowRow che va a capo» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Jetpack Compose Academy, passa a CoddyKit PRO. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Cosa imparerò in «Una FlowRow che va a capo»?

Costruisca da zero un vero layout a capo. Eserciti Jetpack Compose Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Jetpack Compose Academy?

Non è richiesta alcuna esperienza precedente. Jetpack Compose Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Una FlowRow che va a capo»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Jetpack Compose Academy?

Sì. Ogni lezione Jetpack Compose Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Il modello Measure e Place
  2. Scrivere una Composable Layout
  3. Vincoli e misurazioni intrinseche
  4. Una FlowRow che va a capo
← Torna a Jetpack Compose Academy