ContentScale และการครอบตัด
ปรับให้พอดี เติมเต็ม และครอบตัดภาพอย่างเรียบร้อย
ContentScale และการครอบตัด เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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! 🔲
คำถามที่พบบ่อย
บทเรียน “ContentScale และการครอบตัด” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ContentScale และการครอบตัด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ContentScale และการครอบตัด”
ปรับให้พอดี เติมเต็ม และครอบตัดภาพอย่างเรียบร้อย คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “ContentScale และการครอบตัด” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- Composable Image
- ไอคอน Material ด้วย Icon
- ContentScale และการครอบตัด
- ตัดและกำหนดรูปทรงให้ภาพ