Created
November 28, 2021 14:02
-
-
Save mustafayigitt/0e814b2dabd0256229efd70e235ddb3a to your computer and use it in GitHub Desktop.
Collection(Recyclerview)example with Jetpack Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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