【发布时间】:2021-08-19 13:19:25
【问题描述】:
我想显示具有以下规则的图像:
- 图像是远程的,需要在运行时加载。
- 在加载之前,我们不知道图片的大小。
-
Image视图应占父视图的全部宽度,并应自动调整其高度以匹配远程加载的图像,以免发生裁剪/拉伸。
我尝试使用Coil dependency,我有这个代码:
Image(
painter = rememberImagePainter(viewModel.fullImageUrl),
contentDescription = null,
contentScale = ContentScale.FillHeight,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(3.21428f) // TODO: Figure out how to set height/ratio based on image itself
)
当我删除Image 的contentScale 和modifier 时,它的高度似乎总是为零。我不确定我应该怎么做才能使Image 填充其父级的最大宽度,同时在 Coil 加载图像文件后确定其自身的大小。
【问题讨论】:
标签: android android-jetpack-compose coil