ContentScale e ritaglio
Adatti, riempia e ritagli le immagini in modo ordinato.
ContentScale e ritaglio è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 3 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 Image and Box Disagree
Your image has its own aspect ratio, but your layout slot has another. ContentScale decides how the picture fits into that space.
The Aspect Ratio Problem
Force a wide photo into a square and it can stretch or squash. ContentScale gives you sane rules so pictures never look distorted by accident.
Crop Fills and Trims
The most common choice is ContentScale.Crop. It fills the whole slot and trims any overflow, so the frame is always full with no gaps.
Image(painter = p, contentDescription = null,
contentScale = ContentScale.Crop)Fit Shows Everything
ContentScale.Fit shrinks the image until it all fits inside the slot. Nothing is cut off, but you may see empty space on two sides.
FillBounds Can Distort
ContentScale.FillBounds stretches the image to fill both dimensions exactly. It guarantees no gaps but will warp the aspect ratio.
Width or Height Only
Need to fill just one axis? FillWidth and FillHeight scale to match that single dimension while keeping the ratio.
Inside Crops, None Does Not
Inside only shrinks when too big and never enlarges, while None draws at original size, cropping if it overflows.
Crop Needs a Bounded Size
Crop only has an effect when the Image has fixed bounds. Give it a size or fillMaxWidth with a height, or there is nothing to crop into.
Image(painter = p, contentDescription = null,
modifier = Modifier.size(120.dp), contentScale = ContentScale.Crop)Align Within the Frame
When Fit leaves empty space, the alignment argument decides where the image sits, such as Center or TopStart.
Image(painter = p, contentDescription = null, alignment = Alignment.TopCenter)Crop for Thumbnails
Thumbnails and avatars almost always use Crop. It guarantees a clean, gap-free tile no matter the source photo dimensions.
Pick by Intent
Choose by what matters: use Fit when the whole image must be visible, and Crop when a full, edge-to-edge frame matters more.
Quick Check
You want an avatar tile that is always completely filled with no empty space. Which ContentScale fits best?
Recap: Scaling Images
You can now choose ContentScale wisely: Crop to fill, Fit to show all, and align the result. Next: clipping into shapes! 🔲
Domande Frequenti
La lezione «ContentScale e ritaglio» è gratuita?
Sì — il testo completo di «ContentScale e ritaglio» è 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 «ContentScale e ritaglio»?
Adatti, riempia e ritagli le immagini in modo ordinato. 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 3 di 4.
Quanto tempo richiede la lezione «ContentScale e ritaglio»?
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
- La Composable Image
- Icone Material con Icon
- ContentScale e ritaglio
- Ritagliare e dare forma alle immagini