赞
踩
在Jetpackcompose中使用列表要是用LazyColumn和item
- @Composable
- fun CreateDrawerLayout() {
- val list = mutableListOf<Student>()
- for (i in 0..33) {
- list.add(Student("学生${i}", i))
- }
- LazyColumn(modifier = Modifier.fillMaxWidth()) {
- items(list.size) {
- Text(
- text = "items:姓名:${list[it].name},年龄${list[it].age}岁",
- fontSize = 18.sp
- )
- Spacer(modifier = Modifier.height(10.dp))
- }
-
- itemsIndexed(items = list) { index: Int, item: Student ->
- Text(
- text = "itemsIndexed:姓名:${item.name},年龄${item.age}岁",
- fontSize = 18.sp, modifier = Modifier.clickable {
-
- })
- Spacer(modifier = Modifier.height(10.dp))
- }
-
- list.forEachIndexed { index, student ->
- item {
- Text(
- text = "forEachIndexed:姓名:${student.name},年龄${student.age}岁",
- fontSize = 18.sp
- )
- Spacer(modifier = Modifier.height(10.dp))
- }
- }
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。