์ง๋ ํฌ์คํ
https://rkdrkd-history.tistory.com/43
์ด๋ฒ ํฌ์คํ ์์๋ ์ง๋ ํฌ์คํ ์์ ๋ค๋ค๋ compose recyclerview๋ฅผ ์ด์ฉํด ์ค์ต์ ํด๋ณด๊ฒ ๋ค.
์ฌ์ฉ์์ ์ ๋ณด๋ฅผ ๋ด๋ ๋ฐ์ดํฐ ํด๋์ค ์์ฑ
data class Practice2Data(
val name: String,
val age: Int,
val phoneNum: String
)
๊ฐ๋จํ๊ฒ ์ด๋ฆ, ๋์ด, ์ ํ๋ฒํธ๋ง ์ค๋ดค๋ค.
recyclerView ์์ดํ ์์ฑ
@Composable
fun ExampleItem(item: Practice2Data) {
Card(
modifier = Modifier
.padding(10.dp)
.fillMaxWidth()
.height(100.dp)
) {
// ๋ฐฐ๊ฒฝ ๋ฐ์ค
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.LightGray)
.padding(start = 15.dp, end = 15.dp)
) {
}
Box(
contentAlignment = Alignment.CenterStart
) {
Column(modifier = Modifier.offset(x = 10.dp)) {
Text(text = "์ด๋ฆ:"+item.name, modifier = Modifier.offset(y = (-5).dp))
Text(text = "๋์ด:"+item.age.toString(), modifier = Modifier.offset(y = 5.dp))
}
}
Box(
contentAlignment = Alignment.CenterEnd,
modifier = Modifier.offset(x = (-5).dp)
) {
Text(text = "phone:"+item.phoneNum)
}
}
}
recyclerview ์์ฑ
@Preview(showBackground = true)
@Composable
fun DefaultPreview3() {
val item = mutableListOf<Practice2Data>()
item.add(0, Practice2Data("name1", 16, "010-1234-5678"))
item.add(1, Practice2Data("name2", 18, "010-2345-6789"))
item.add(2, Practice2Data("name3", 20, "010-3456-7890"))
item.add(3, Practice2Data("name4", 18, "010-1111-2222"))
item.add(4, Practice2Data("name5", 20, "010-2222-3333"))
item.add(5, Practice2Data("name6", 24, "010-3333-4444"))
item.add(6, Practice2Data("name7", 15, "010-4444-5555"))
ComposeUITheme {
LazyColumn {
itemsIndexed(item) { index, data ->
ExampleItem(item = data)
}
}
}
}
์คํ ๊ฒฐ๊ณผ
์ ์์ ์ผ๋ก ์ ์ถ๋ ฅ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
728x90
'๐ฑ| Android > ๐ | Jetpack' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android, Kotlin] Android Activity์ lifeCycle ์ ๋ฆฌ (0) | 2023.03.17 |
---|---|
[Android, Kotlin] Compose UI ์ ๋ฆฌ(5) (0) | 2023.03.13 |
[Android, Kotlin] Compose UI ์ ๋ฆฌ(3) (0) | 2022.12.04 |
[Android, Kotlin] Compose UI ์ ๋ฆฌ(2) (0) | 2022.12.03 |
[Android, Kotlin] Compose UI ์ ๋ฆฌ(1) (0) | 2022.12.01 |