Build: Simple Image Display
This screen shows an image centered on the screen with a description below it.
Target UI
--------------------- | | | | | [Image] | | | | | | This is a cat. | | | ---------------------
--------------------- | | | | | [Image] | | | | | | This is a cat. | | | ---------------------
import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp @Composable fun SimpleImageScreen() { Surface(modifier = Modifier.fillMaxSize()) { Column( modifier = Modifier.padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { // TODO: Add Image composable here // TODO: Add Text composable below the image } } }
import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp @Composable fun SimpleImageScreen() { Surface(modifier = Modifier.fillMaxSize()) { Column( modifier = Modifier.padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { Image( painter = painterResource(id = R.drawable.cat_image), contentDescription = "Cat image" ) Text( text = "This is a cat.", style = MaterialTheme.typography.bodyLarge, modifier = Modifier.padding(top = 8.dp) ) } } }
We use the Image composable to show the picture from drawable resources. The painterResource function loads the image by its resource ID R.drawable.cat_image. We add a contentDescription for accessibility so screen readers can describe the image. Below the image, a Text composable shows a simple description. The Column centers both horizontally and adds padding around the content for nice spacing.
--------------------- | | | | | [Image] | | | | | | This is a cat. | | | ---------------------
Image composable in Android Jetpack Compose?logo in an Image composable?Image(painter = painterResource(id = R.drawable.ic_launcher), contentDescription = null)
Image(painter = painterResource(), contentDescription = "Icon")
profile_pic with a circular shape and a description for accessibility. Which code snippet correctly achieves this?Pass the test and this pattern moves unknown