gpt4 book ai didi

android - 如何检测 ImagePainter 何时使用 Jetpack Compose 从 Web 加载照片?

转载 作者:行者123 更新时间:2023-12-05 04:36:33 29 4
gpt4 key购买 nike

我想通过 URL 链接显示网络图像。我想显示进度条直到加载图像,然后隐藏进度条并显示图像。如何检测画家何时加载图像?

HorizontalPager(count = photoUrlList.size, state = photoPagerState) { page ->
var shouldBeProgressBarDisplayed by mutableStateOf(true)

val painter = rememberImagePainter(photoUrlList[page], builder = {
this.listener(
onSuccess = { request, ex ->
shouldBeProgressBarDisplayed = false
})
})

if (shouldBeProgressBarDisplayed) {
ProgressBar()
} else {
Image(
painter = painter,
modifier = Modifier
.padding(vertical = 100.dp)
.fillMaxSize(),
contentScale = ContentScale.Crop,
contentDescription = ""
)
}
}

最佳答案

你可以使用painter.state来实现这一点

HorizontalPager(count = photoUrlList.size, state = photoPagerState) { page ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(vertical = 100.dp)
) {
val painter = rememberImagePainter(
data = photoUrlList[page],
builder = {
crossfade(500)
})

val painterState = painter.state

if (painterState is ImagePainter.State.Loading) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = MaterialTheme.colors.secondary
)
} else {
Image(
painter = painter,
modifier = Modifier
.fillMaxSize(),
contentScale = ContentScale.Crop,
contentDescription = ""
)
}
}
}

关于android - 如何检测 ImagePainter 何时使用 Jetpack Compose 从 Web 加载照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70816412/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com