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())
                    })
                }
            })
        }

    }
}
相关推荐
千里马学框架5 天前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
美狐美颜SDK开放平台5 天前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
AFinalStone5 天前
Android7 SystemUI源码解析(七)Keyguard锁屏模块深度解析
android·systemui
致远ccc5 天前
Google Play 上架前如何测试 App?多国家 Android 环境测试
android·app测试·googleplay·多国家应用测试
ttyyttemo5 天前
Kotlin 协程中的 Job 结构化并发与取消
android
sun0077005 天前
tbox 4g/5g切换,导致wan ip 改变,导致车机旧网络不可用。需要重启车机才行
android
ai2work5 天前
ch23 综合复刻:从零做一个最小可用版本(capstone)
kotlin
其实防守也摸鱼5 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
ai2work5 天前
ch21 签名、校验与发版
kotlin
AFinalStone5 天前
Android7 SystemUI 源码解析(四)NavigationBar 导航栏与 SystemBars
android·systemui