Uma FlowRow que Quebra Linhas
Crie do zero um layout real com quebra de linha.
Uma FlowRow que Quebra Linhas é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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. ✅
Perguntas Frequentes
A aula “Uma FlowRow que Quebra Linhas” é grátis?
Sim — o texto completo de “Uma FlowRow que Quebra Linhas” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.
O que vou aprender em “Uma FlowRow que Quebra Linhas”?
Crie do zero um layout real com quebra de linha. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Jetpack Compose Academy?
Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Uma FlowRow que Quebra Linhas”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Jetpack Compose Academy?
Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- O Modelo de Medição e Posicionamento
- Escrevendo uma Composable de Layout
- Restrições e Medições Intrínsecas
- Uma FlowRow que Quebra Linhas