gpt4 book ai didi

android - Jetpack Compose 中图像的无限旋转

转载 作者:行者123 更新时间:2023-12-04 16:37:11 44 4
gpt4 key购买 nike

如何让我的图像无限旋转?
这是我的代码,但动画不起作用

 val angle: Float by animateFloatAsState(
targetValue = 360F,
animationSpec = infiniteRepeatable(
tween(2000))
)
Image(
painter = painterResource(R.drawable.sonar_scanner),
"image",
Modifier
.fillMaxSize()
.rotate(angle),
contentScale = ContentScale.Fit
)

最佳答案

您可以使用 InfiniteTransition 使用 rememberInfiniteTransition .
就像是

val infiniteTransition = rememberInfiniteTransition()
val angle by infiniteTransition.animateFloat(
initialValue = 0F,
targetValue = 360F,
animationSpec = infiniteRepeatable(
animation = tween(2000, easing = LinearEasing)
)
)
只是一个注释。
而不是使用
Modifier.rotate(angle)
您可以使用
     Modifier
.graphicsLayer {
rotationZ = angle
}
正如您可以查看文档:

Prefer this version when you have layer properties backed by a androidx.compose.runtime.State or an animated value as reading a state inside block will only cause the layer properties update without triggering recomposition and relayout.

关于android - Jetpack Compose 中图像的无限旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68381193/

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