Challenge - 5 Problems
Image Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will this Image composable display?
Consider this Kotlin Compose code snippet:
What will the user see on the screen?
Image( painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "App icon", modifier = Modifier.size(64.dp) )
What will the user see on the screen?
Android Kotlin
Image( painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "App icon", modifier = Modifier.size(64.dp) )
Attempts:
2 left
💡 Hint
Think about what painterResource and modifier.size do in Compose Image.
✗ Incorrect
The Image composable uses painterResource to load a drawable resource. The modifier.size(64.dp) sets the image size to 64x64 dp. The contentDescription provides accessibility info. So the image will appear as a 64x64 dp icon with the given description.
📝 Syntax
intermediate2:00remaining
Which option correctly loads a network image in Compose?
You want to load an image from a URL in Jetpack Compose. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Remember which library provides rememberImagePainter for network images.
✗ Incorrect
Option A uses rememberImagePainter from the Coil library to load images from URLs in Compose. Other options use invalid or unsupported functions for network images.
❓ lifecycle
advanced2:00remaining
What happens if you forget contentDescription in Image composable?
In Jetpack Compose, what is the impact of omitting the contentDescription parameter in an Image composable?
Android Kotlin
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground))
Attempts:
2 left
💡 Hint
Think about accessibility and screen readers.
✗ Incorrect
If contentDescription is omitted or null, accessibility services skip the image, which can confuse users relying on screen readers. The app does not crash and the image still displays.
🔧 Debug
advanced2:00remaining
Why does this Image not show in Compose?
Given this code:
Why does the image not appear on screen?
Image( painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Icon", modifier = Modifier.size(0.dp) )
Why does the image not appear on screen?
Android Kotlin
Image( painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Icon", modifier = Modifier.size(0.dp) )
Attempts:
2 left
💡 Hint
Check the size modifier values.
✗ Incorrect
Setting Modifier.size(0.dp) makes the composable have zero width and height, so it is not visible on screen. The image is loaded correctly but not shown.
🧠 Conceptual
expert3:00remaining
How does contentScale affect Image composable rendering?
In Jetpack Compose, what is the effect of setting contentScale = ContentScale.Crop on an Image composable?
Android Kotlin
Image( painter = painterResource(id = R.drawable.sample), contentDescription = "Sample", modifier = Modifier.size(100.dp, 50.dp), contentScale = ContentScale.Crop )
Attempts:
2 left
💡 Hint
Think about how cropping works with aspect ratio preservation.
✗ Incorrect
ContentScale.Crop scales the image to fill the target size and crops any overflow, preserving the image's aspect ratio. This means parts of the image may be cut off to avoid distortion.