繁体   English   中英

Jetpack Compose LazyVerticalGrid 口吃

[英]Jetpack Compose LazyVerticalGrid stuttering

我正在迁移我的应用程序,对于网格视图,我使用了 LazyVerticalGrid,它使用 coilPainter 加载图像,但滚动时断断续续很多,而且感觉滞后。 有没有人对此有解决方案或更好的实现?

    val photos: List<Photo>? by photosViewModel.photosLiveData.observeAsState(null)

    Surface(modifier = Modifier.fillMaxSize()) {
        Box(
            modifier = Modifier.fillMaxSize()
        ) {
            LazyVerticalGrid(
                cells = GridCells.Fixed(3)
            ) {
                photos?.let { photosList ->
                    items(photosList) { photo ->
                        Image(
                            modifier = Modifier.padding(2.dp).clickable {
                                photosViewModel.onPhotoClicked(photo)
                            },
                            painter = rememberCoilPainter(photo.url),
                            contentDescription = stringResource(R.string.cd_details_photo),
                            contentScale = ContentScale.Fit,
                            alignment = Alignment.Center,
                        )

                    }
                }
            }
        }
    }

更新

试图移动rememberCoilPainter以上Imageval painter = rememberCoilPainter(photo.url)并使用painter内的Image没有工作

items需要一个额外的参数key ,将此参数分配给一个唯一值,例如列表中每张照片的索引,如果您不知道这与滚动卡顿有什么关系? 或者我到底在说什么? 查看以下文档以获取详细说明:

https://developer.android.com/jetpack/compose/lifecycle#add-info-smart-recomposition

将我的 compose 图像加载库更新为线圈组合后,我被迫将大小设置为请求构建器或图像本身。 卡顿的问题是因为允许照片加载原始尺寸,因此重新构图进行了多次,加载图像必须等待图片加载。 通过将 e固定高度设置为 Image 解决了该问题,因为创建了 Images() 并且仅对内部图片进行了重新组合,而不是针对具有不同高度的 Image 本身。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM