Répartition et alignement
Positionnez et espacez précisément les éléments enfants.
Répartition et alignement est une leçon Jetpack Compose Academy gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Jetpack Compose Academy, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Jetpack Compose Academy comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
Two Words, Two Jobs
Layout control comes down to arrangement and alignment. They sound similar but they do different jobs. Let's untangle them. 🧭
Arrangement: Along the Main Axis
Arrangement controls spacing along the layout's main axis: vertical for a Column, horizontal for a Row.
Alignment: Across the Cross Axis
Alignment controls position on the other axis: horizontal in a Column, vertical in a Row. It lines children up sideways.
Grouping at One End
Arrangement.Top, Center, and Bottom pack children together at one end of a Column, leaving the rest as empty space.
Column(verticalArrangement = Arrangement.Center) {
Text("A")
Text("B")
}Spreading Children Out
Use SpaceBetween, SpaceAround, or SpaceEvenly to distribute extra space among children instead of bunching them up.
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
Text("A")
Text("B")
Text("C")
}SpaceBetween vs SpaceEvenly
SpaceBetween hugs the edges with no outer gaps, while SpaceEvenly adds equal gaps everywhere, including before the first and after the last child.
Fixed Gaps with spacedBy
For a consistent gap, use Arrangement.spacedBy. It inserts the exact distance you give between every adjacent child.
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text("A")
Text("B")
}Column's Cross-Axis Alignment
In a Column the cross axis is horizontal, so horizontalAlignment chooses Start, CenterHorizontally, or End for the children.
Column(horizontalAlignment = Alignment.End) {
Text("Right side")
}Row's Cross-Axis Alignment
In a Row the cross axis is vertical, so verticalAlignment picks Top, CenterVertically, or Bottom for the children.
Row(verticalAlignment = Alignment.Bottom) {
Text("Aligned bottom")
}Combine Both for Layout
You usually set both at once: arrangement spaces children along the main axis while alignment positions them on the cross axis.
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) { Text("Dead center") }Effect Needs Extra Space
Arrangement only shows when the container is bigger than its children. A wrap-content Column has no spare room to redistribute.
Quick Check
Let's confirm which axis each setting controls.
Recap: Arrangement & Alignment
You learned the split: arrangement spaces children along the main axis, alignment positions them on the cross axis. Combine both for precise layouts.
Questions Fréquemment Posées
La leçon « Répartition et alignement » est-elle gratuite ?
Oui — le texte complet de « Répartition et alignement » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Jetpack Compose Academy, passe à CoddyKit PRO. Le cours Jetpack Compose Academy comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Répartition et alignement » ?
Positionnez et espacez précisément les éléments enfants. Tu pratiques Jetpack Compose Academy avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Jetpack Compose Academy ?
Aucune expérience préalable n'est requise. Jetpack Compose Academy sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.
Combien de temps prend la leçon « Répartition et alignement » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Jetpack Compose Academy ?
Oui. Chaque leçon Jetpack Compose Academy inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Column : empiler verticalement
- Row : placer côte à côte
- Box : superposer et faire chevaucher
- Répartition et alignement