android compose LazyVerticalGrid上下滚动的网格布局 使用

android compose LazyVerticalGrid上下滚动的网格布局 使用

复制代码
/**
 * Author : wn
 * Email : maoning20080809@163.com
 * Date : 2026/1/9 22:00
 * Description : LazyVerticalGrid滚动的网格布局
 */
class LazyVerticalGridActivity : ComponentActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            testLazyVerticalGrid()
        }
    }

    @Preview
    @Composable
    private fun testLazyVerticalGrid(){
        val items = (1..100).toList()
        Column() {
            Spacer(modifier = Modifier.height(20.dp))
            Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center){
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    Text(text = "LazyVerticalGrid上下滚动的网格布局", fontSize = 20.sp, color = Color.Green)
                    Spacer(modifier = Modifier.height(20.dp))
                    Text(text = "排列从左到右  -> ", fontSize = 30.sp, color = Color.Black)
                }
            }

            LazyVerticalGrid(GridCells.Fixed(4), contentPadding = PaddingValues(16.dp), content = {
                items(items){ item ->
                    Box(modifier = Modifier.size(50.dp).padding(6.dp)
                        .background(Color.Green), contentAlignment = Alignment.Center, content = {
                        Text(text = item.toString())
                    })
                }
            })
        }

    }
}
相关推荐
好的佩奇2 小时前
Dart 之扩展方法
android·flutter·dart
三少爷的鞋3 小时前
换个思路理解:非阻塞挂起
android
好的佩奇4 小时前
蓝牙之经典蓝牙
android·flutter·蓝牙
传奇开心果编程6 小时前
【Flutter踩坑排雷】第19课:路由硬编码坑|字符串路由书写错误,页面跳转失败排查
android·flutter·ios·移动开发·跨平台·ui框架·声明式ui
微小的鱼9 小时前
Linux的渲染与显示系统链路
android·java·linux
道尔柯南21 小时前
C++ string 类详解:从常用接口到深拷贝,彻底掌握字符串处理
android·java·c++
唐诺1 天前
5、Android JNI 动态注册中的“签名“详解
android·jni
zhaoshuzhaoshu1 天前
Android 系统启动与调试中的日志抓取方式全解析
android
雨声不在1 天前
android 动画掉帧
android
在多学一点1 天前
MYSQL第二次作业
android·数据库·mysql