首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jetpack组合中的RotateAnimation

jetpack组合中的RotateAnimation
EN

Stack Overflow用户
提问于 2022-06-10 17:50:43
回答 1查看 95关注 0票数 0

我有这个RotateAnimation来自于GitHub上的一个项目,我想将同样的旋转应用于我的图像(指南针内箭头)

以下是RotateAnimation的参数:

公共RotateAnimation(浮点fromDegrees,浮点toDegrees,int pivotXType,浮点pivotXValue,int pivotYType,浮点pivotYValue)

这是我的代码:

代码语言:javascript
复制
        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)

如何在作曲中应用相同的动画?

EN

回答 1

Stack Overflow用户

发布于 2022-06-10 19:43:57

简单的例子,但你可以做到这样;

代码语言:javascript
复制
@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
    ) {}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72578130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档