チップを折り返すFlowRow
実際に折り返すレイアウトをゼロから作ります。
「チップを折り返すFlowRow」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. ✅
よくある質問
「チップを折り返すFlowRow」レッスンは無料ですか?
はい。「チップを折り返すFlowRow」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「チップを折り返すFlowRow」で何を学びますか?
実際に折り返すレイアウトをゼロから作ります。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「チップを折り返すFlowRow」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- MeasureとPlaceのモデル
- Layout Composableを書く
- 制約と固有サイズ測定
- チップを折り返すFlowRow