Skip to content

Instantly share code, notes, and snippets.

@mustafayigitt
Created November 28, 2021 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafayigitt/0e814b2dabd0256229efd70e235ddb3a to your computer and use it in GitHub Desktop.
Save mustafayigitt/0e814b2dabd0256229efd70e235ddb3a to your computer and use it in GitHub Desktop.
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