weightと柔軟なサイズ設定
行や列のスペースを比例配分します。
「weightと柔軟なサイズ設定」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Flexible Space
Sometimes you want children to share space, not take fixed sizes. The weight modifier divides leftover room proportionally. ⚖️
Where weight Lives
weight works only inside a Row or Column. It is part of the layout scope those containers provide to their children.
Equal Split
Give two children the same weight and they share the space evenly, each taking half of what is available.
Box(Modifier.weight(1f))
Box(Modifier.weight(1f))Uneven Split
Weights are ratios. A child with weight(2f) gets twice the space of a sibling with weight(1f).
Box(Modifier.weight(2f))
Box(Modifier.weight(1f))Fixed Plus Flexible
Mix and match: give one child a fixed size and let another use weight to absorb whatever space remains.
Box(Modifier.width(80.dp))
Box(Modifier.weight(1f))Push to the Edge
A single weight on a spacer acts like a push, sending the next child all the way to the far end of the row.
Text("Left")
Spacer(Modifier.weight(1f))
Text("Right")Weights Run First
Compose measures fixed children first, then splits the leftover space among weighted ones. That is why weight needs siblings to push against.
The fill Flag
By default a weighted child fills its share. Pass fill = false to let it stay smaller than the space it was given.
Modifier.weight(1f, fill = false)Weighted Columns
The same idea works vertically. In a Column, weight divides the leftover height instead of width.
Column {
Box(Modifier.weight(1f))
Box(Modifier.weight(1f))
}Responsive by Design
Because weights are ratios, your layout scales gracefully across phone and tablet widths without hardcoded numbers.
A Common Pattern
Label on the left, value filling the rest: a weighted row is the classic recipe for clean settings and list rows.
Row {
Text("Name")
Text("Sam", Modifier.weight(1f))
}Quick Check
Two children sit in a Row with weight(3f) and weight(1f). How is the space shared?
Recap
You can now share space flexibly. weight splits leftover room by ratio inside Rows and Columns for responsive layouts. 🎯
よくある質問
「weightと柔軟なサイズ設定」レッスンは無料ですか?
はい。「weightと柔軟なサイズ設定」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「weightと柔軟なサイズ設定」で何を学びますか?
行や列のスペースを比例配分します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「weightと柔軟なサイズ設定」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。