Il modello Measure e Place
Comprenda il layout a passaggio singolo di Compose.
Il modello Measure e Place è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 1 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.
When Built-In Layouts Are Not Enough
Column, Row, and Box cover most screens. But sometimes you need total control over where children go. That is when you build a custom layout. 🎨
Compose Lays Out in One Pass
Unlike the old View system, Compose measures and places everything in a single pass. There is no expensive measure-then-measure-again cycle.
Two Steps: Measure, Then Place
Every layout does two things in order. First it measures each child to learn its size. Then it places each child at a chosen position.
Measurables Are Children Not Yet Sized
A parent receives its children as measurables. A measurable is a child you have not measured yet, like a parcel before you weigh it. 📦
Measuring Produces a Placeable
Call measure on a measurable and you get a placeable back. The placeable knows its final width and height and is ready to be positioned.
val placeable = measurable.measure(constraints)
val w = placeable.widthConstraints Set the Size Limits
When you measure, you pass constraints: the min and max width and height the child is allowed. The child picks a size within those bounds.
Measure Each Child Exactly Once
The single-pass rule means you must measure each child only once. Measuring the same child twice throws an error at runtime.
The Parent Decides Its Own Size
After measuring children, the parent reports its own width and height. It usually sizes itself to wrap the children it just measured.
layout(width, height) {
// place children here
}Placing Sets Each Child's Position
Inside the layout block you call placeRelative on each placeable, giving it an x and y. That is where the child lands on screen.
placeable.placeRelative(x = 0, y = 0)placeRelative Respects Direction
Prefer placeRelative over place. It automatically mirrors positions for right-to-left languages, so your layout works everywhere. 🌍
This Model Powers Every Layout
Column, Row, and your future custom layouts all follow this same measure-then-place rhythm. Learn it once and you understand all of Compose layout.
Quick Check
What do you get back after measuring a measurable?
Recap: The Measure & Place Model
Compose lays out in one pass: measure each child once within constraints to get placeables, then place them. This model drives every layout you will build. ✅
Domande Frequenti
La lezione «Il modello Measure e Place» è gratuita?
Sì — il testo completo di «Il modello Measure e Place» è 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 «Il modello Measure e Place»?
Comprenda il layout a passaggio singolo di Compose. 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 1 di 4.
Quanto tempo richiede la lezione «Il modello Measure e Place»?
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
- Il modello Measure e Place
- Scrivere una Composable Layout
- Vincoli e misurazioni intrinseche
- Una FlowRow che va a capo