我有这个RotateAnimation来自于GitHub上的一个项目,我想将同样的旋转应用于我的图像(指南针内箭头)
以下是RotateAnimation的参数:
公共RotateAnimation(浮点fromDegrees,浮点toDegrees,int pivotXType,浮点pivotXValue,int pivotYType,浮点pivotYValue)
这是我的代码:
angleCompass.value = -angle
val an = RotateAnimation(
-currentAngle, -angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f
)
currentAngle = azimuth
an.duration = 500
an.repeatCount = 0
an.fillAfter = true
binding.imgCompass.startAnimation(an)
val anim = RotateAnimation(
-currentAngle + qiblaDir, -azimuth,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f
)
angleNeedle.value = -azimuth
currentAngle = azimuth
anim.duration = 500
anim.repeatCount = 0
anim.fillAfter = true
binding.imgQiblaArrow.startAnimation(anim)如何在作曲中应用相同的动画?
发布于 2022-06-10 19:43:57
简单的例子,但你可以做到这样;
@Composable
fun AnimatableSurface() {
val currentAngle = 0f
val angle = 90f
val rotateAnim = remember { Animatable(currentAngle) }
LaunchedEffect(key1 = true){
rotateAnim.animateTo(angle, tween(2000))
}
Surface(
modifier = Modifier.size(100.dp).rotate(rotateAnim.value),
color = Color.Red
) {}
}https://stackoverflow.com/questions/72578130
复制相似问题