首页 > 解决方案 > android: 播放 Lottie 动画片段

问题描述

我认为问题的标题说明了一切,

我虽然想添加一个动画监听器,但无法得到我想要的结果。

     //lottie_toggle is the view id

     lottie_toggle.addAnimatorUpdateListener {valueAnimator->
        val progress = (valueAnimator.animatedValue as Float * 100).toInt()

        if (progress==100 ){
            lottie_toggle.cancelAnimation()
            lottie_toggle.progress=0f
        }
        if (progress==50 ){
            lottie_toggle.cancelAnimation()
            lottie_toggle.progress=0.5f
        }
    }

标签: androidlottie

解决方案


似乎设置最小/最大帧是一种合适的方式,

//if the animation has 60 frames
lottie_toggle.setMinAndMaxFrame(0,30) //to play the first half
lottie_toggle.setMinAndMaxFrame(30,60) //to play the second half

推荐阅读