0
0
Android Kotlinmobile~10 mins

Image composable in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display an image from a drawable resource using Image composable.

Android Kotlin
Image(painter = painterResource(id = [1]), contentDescription = "Sample image")
Drag options to blanks, or click blank then click option'
AR.layout.activity_main
BR.string.app_name
CR.color.primary
DR.drawable.ic_launcher_foreground
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or layout resource instead of a drawable resource.
Forgetting to use painterResource to load the drawable.
2fill in blank
medium

Complete the code to set the content scale of the Image composable to crop the image.

Android Kotlin
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", contentScale = [1])
Drag options to blanks, or click blank then click option'
AContentScale.Crop
BContentScale.FillBounds
CContentScale.Fit
DContentScale.Inside
Attempts:
3 left
💡 Hint
Common Mistakes
Using ContentScale.Fit which fits the whole image but may leave empty space.
Using ContentScale.FillBounds which stretches the image.
3fill in blank
hard

Fix the error in the code by completing the modifier to add padding around the Image composable.

Android Kotlin
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", modifier = Modifier.[1](16.dp))
Drag options to blanks, or click blank then click option'
Apadding
BfillMaxSize
Cbackground
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using size instead of padding which changes the composable size.
Using background which changes color but not space.
4fill in blank
hard

Fill both blanks to create an Image composable that fills the max width and has a rounded corner shape.

Android Kotlin
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", modifier = Modifier.[1]().clip(RoundedCornerShape([2])))
Drag options to blanks, or click blank then click option'
AfillMaxWidth
BfillMaxHeight
C8.dp
D16.dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using fillMaxHeight instead of fillMaxWidth.
Using too small or no corner radius.
5fill in blank
hard

Fill all three blanks to create an Image composable with a content description, a tint color, and a size modifier.

Android Kotlin
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = [1], colorFilter = ColorFilter.tint([2]), modifier = Modifier.[3](48.dp))
Drag options to blanks, or click blank then click option'
A"App icon"
BColor.Red
Csize
Dpadding
Attempts:
3 left
💡 Hint
Common Mistakes
Using padding instead of size for the modifier.
Not providing a content description string.
Using a color without ColorFilter.tint.