0
0
Android Kotlinmobile~20 mins

Image composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will this Image composable display?
Consider this Kotlin Compose code snippet:
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)
)
AAn error because painterResource cannot be used inside Image.
BA 64x64 dp sized image showing the app's launcher foreground icon with accessibility label 'App icon'.
CA full screen image ignoring the size modifier.
DA blank space because contentDescription is not null.
Attempts:
2 left
💡 Hint
Think about what painterResource and modifier.size do in Compose Image.
📝 Syntax
intermediate
2: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?
AImage(painter = rememberImagePainter("https://example.com/image.png"), contentDescription = "Network image")
BImage(painter = painterResource("https://example.com/image.png"), contentDescription = "Network image")
CImage(painter = loadImage("https://example.com/image.png"), contentDescription = "Network image")
DImage(painter = ImageBitmap.imageResource("https://example.com/image.png"), contentDescription = "Network image")
Attempts:
2 left
💡 Hint
Remember which library provides rememberImagePainter for network images.
lifecycle
advanced
2: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))
AThe image will not display on the screen.
BThe app will crash at runtime with a NullPointerException.
CThe image will display but with a default description 'Image'.
DThe image will be ignored by accessibility services, making the app less accessible.
Attempts:
2 left
💡 Hint
Think about accessibility and screen readers.
🔧 Debug
advanced
2:00remaining
Why does this Image not show in Compose?
Given this code:
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)
)
ABecause contentDescription is too short.
BBecause painterResource cannot load drawable resources.
CBecause the size modifier sets width and height to zero, making the image invisible.
DBecause Image composable requires a background color to display.
Attempts:
2 left
💡 Hint
Check the size modifier values.
🧠 Conceptual
expert
3: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
)
AThe image is scaled to fill the 100x50 dp area, cropping parts that don't fit while preserving aspect ratio.
BThe image is stretched to exactly 100x50 dp, ignoring aspect ratio.
CThe image is scaled down to fit inside 100x50 dp without cropping, possibly leaving empty space.
DThe image is displayed at its original size ignoring the modifier size.
Attempts:
2 left
💡 Hint
Think about how cropping works with aspect ratio preservation.