【发布时间】:2021-07-30 00:49:34
【问题描述】:
我需要使用 Coil 通过 url 在我的应用程序中显示图像,但无法加载此图像。我按照官方文档https://coil-kt.github.io/coil/compose/.
implementation "io.coil-kt:coil-compose:1.3.1"
@Composable
fun ProfilePicture(profilePicture: String, online: Boolean) {
Card(
shape = CircleShape,
border = BorderStroke(
width = 2.dp,
color = if (online) MaterialTheme.colors.lightGreen else Color.Red
),
modifier = Modifier.padding(16.dp),
elevation = 4.dp
) {
Image(
painter = rememberImagePainter(
data = profilePicture,
builder = {
transformations(CircleCropTransformation())
}
),
modifier = Modifier.size(72.dp),
contentDescription = "Profile picture"
)
}
}
更新
UserModel 示例
UserModel(
name = "John Doe",
profilePicture = "https://randomuser.me/api/portraits/men/32.jpg",
online = true
)
【问题讨论】:
-
你可以尝试在里面放一个静态网址,这样你就可以确定线圈是问题所在
-
请提供一个无效的
profilePicture示例 -
我用 UserModel 示例更新了我的问题。
-
@Philip 感谢您的反馈。我在物理设备上测试它并且工作正常,但在我所有的模拟器版本上都不起作用
-
@GustavoFaria,我和你有同样的问题:模拟器中没有加载图像,但在真实设备上可以正常工作。
标签: android android-jetpack-compose coil