Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Collection(Recyclerview)example with Jetpack Compose
val context = LocalContext.current
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 24.dp),
verticalArrangement = Arrangement.spacedBy(20.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
Text(
text = "Hello Compose",
style = MaterialTheme.typography.h2,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
}
items(getListItems()) { item ->
Card(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.clickable { item.id printToast context },
shape = RoundedCornerShape(20.dp),
elevation = 0.dp,
backgroundColor = Color(0x4D018786)
) {
Column(
Modifier
.fillMaxWidth()
.wrapContentHeight()
) {
Image(
painter = rememberImagePainter(item.coverImage),
contentDescription = "photo ${item.title}",
modifier = Modifier
.fillMaxWidth()
.height(250.dp)
.align(Alignment.CenterHorizontally),
contentScale = ContentScale.Crop
)
Text(
text = item.title,
style = MaterialTheme.typography.body1,
textAlign = TextAlign.Center,
color = Color.Black,
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(horizontal = 24.dp, vertical = 16.dp)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment