iT邦幫忙

2024 iThome 鐵人賽

DAY 14
0
Mobile Development

從零開始學習 Jetpack Compose系列 第 14

從零開始學習 Jetpack Compose Day13 - LazyColumn與LazyRow

  • 分享至 

  • xImage
  •  

LazyColumn 與 LazyRow

LazyColumn 和 LazyRow 是 Jetpack Compose 中的懶加載列表元件,類似於 RecyclerView,分別用於垂直和水平的佈局,並且適合處理需要加載大量項目的情況。

LazyColumn

@Composable
fun LazyColumnComposable(modifier: Modifier = Modifier) {
    LazyColumn {
        items(20) {
            Card(
                modifier = modifier.padding(20.dp)
            ) {
                Column(
                    modifier = modifier.padding(20.dp)
                ) {
                    Text(
                        text = "Item $it",
                        modifier = modifier,
                        style = MaterialTheme.typography.headlineSmall
                    )
                    Text(
                        text = "content",
                        modifier = modifier.width(200.dp).height(200.dp)
                    )
                    Row {
                        IconButton(onClick = {  }) {
                            Icon(
                                imageVector = Icons.AutoMirrored.Filled.Send,
                                contentDescription = ""
                            )
                        }
                        IconButton(onClick = {  }) {
                            Icon(
                                imageVector = Icons.Filled.AddCircle,
                                contentDescription = ""
                            )
                        }
                        IconButton(onClick = {  }) {
                            Icon(
                                imageVector = Icons.Filled.Create,
                                contentDescription = ""
                            )
                        }
                    }
                }

            }
        }
    }
}

https://raw.githubusercontent.com/jian-fu-hung/ithelp-2024/refs/heads/main/Images/Day13/%E6%88%AA%E5%9C%96%202024-09-28%20%E6%99%9A%E4%B8%8A9.45.03.png

LazyRow

@Composable
fun LazyRowComposable(modifier: Modifier = Modifier) {
    LazyRow {
        items(20) {
            Card(
                modifier = modifier.padding(20.dp)
            ) {
                Column(
                    modifier = modifier.padding(20.dp)
                ) {
                    Text(
                        text = "Item $it",
                        modifier = modifier,
                        style = MaterialTheme.typography.headlineSmall
                    )
                    Text(
                        text = "content",
                        modifier = modifier.width(200.dp).height(200.dp)
                    )
                    Row {
                        IconButton(onClick = { }) {
                            Icon(
                                imageVector = Icons.AutoMirrored.Filled.Send,
                                contentDescription = ""
                            )
                        }
                        IconButton(onClick = { }) {
                            Icon(
                                imageVector = Icons.Filled.AddCircle,
                                contentDescription = ""
                            )
                        }
                        IconButton(onClick = { }) {
                            Icon(
                                imageVector = Icons.Filled.Create,
                                contentDescription = ""
                            )
                        }
                    }
                }

            }
        }
    }
}

https://raw.githubusercontent.com/jian-fu-hung/ithelp-2024/refs/heads/main/Images/Day13/%E6%88%AA%E5%9C%96%202024-09-28%20%E6%99%9A%E4%B8%8A9.46.16.png


上一篇
從零開始學習 Jetpack Compose Day12 - Scaffold
下一篇
從零開始學習 Jetpack Compose Day14 - BottomSheet
系列文
從零開始學習 Jetpack Compose30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言