Jetpack Compose replaces the XML layout + Activity/View imperative model with a declarative one: you describe what the UI should look like for a given state, and Compose handles updating the screen when that state changes.
@Composable
fun MovieCard(movie: Movie, onClick: () -> Unit) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.clickable { onClick() }
) {
Column(modifier = Modifier.padding(16.dp)) {
Text(text = movie.title, style = MaterialTheme.typography.titleMedium)
Text(text = movie.year.toString(), style = MaterialTheme.typography.bodySmall)
}
}
}
A @Composable function is not a widget you instantiate once — it’s a description that Compose can call repeatedly (“recompose”) whenever its inputs change, redrawing only what actually changed rather than the whole screen.
Modifier chains (.fillMaxWidth().padding(8.dp)) replace XML layout attributes — order matters, since each modifier wraps the previous one.
- Image
- SKU
- Rating
- Price
- Stock
- Availability
- Add to cart
- Description
- Content
- Weight
- Dimensions
- Additional information