检测动画何时结束(AnimationListener)

3
我可以使用 Kotlin 以编程方式启动 Lottie 动画,但我无法创建 AnimationListener。如何才能实现呢?首先,我通过 animation_view.progress 使用 if 语句尝试了一下,但不起作用。
        textChanger.setOnClickListener{


                   animation_view.setAnimation("data.json")
                   animation_view.playAnimation()
                   animation_view.loop(false)
        }

我希望它能够检测动画何时完成,以便我可以例如制作Toast。有没有适用于Kotlin的良好Lottie文档?
谢谢您的帮助,我刚开始学习Android和Kotlin。
1个回答

5
你可以查看这里
尝试使用以下代码:
animation_view.addAnimatorListener(object:Animator.AnimatorListener {
    override fun onAnimationRepeat(animation: Animator?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }


    override fun onAnimationEnd(animation: Animator?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onAnimationCancel(animation: Animator?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onAnimationStart(animation: Animator?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}

在React Native - Typescript中,例如使用lottie,这是否可能实现?它可以编译成Android + iOS,因此我对此的Kotlin代码不是很感兴趣,因为我的代码库中没有Kotlin,只有Typescript。我猜Lottie的React Native库中可能会有一个动画监听器实现,但我仍然无法找到它。 - Aj Otto

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接