首先是设置lottie的播放位置:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/my_lottie"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_centerInParent="true"
android:visibility="invisible" />
然后就可以播放lottie了:
// my_lottie(这里就不写findViewById了,我这里直接用id来简单表示一下)
private fun playMyLottie() {
my_lottie.visibility = View.VISIBLE
my_lottie.setAnimation(lottie资源)
my_lottie.playAnimation()
}
如果需要在lottie播放前后等做一些事情的话,还需要加lottie的监听事件:
// my_lottie(这里就不写findViewById了,我这里直接用id来简单表示一下)
my_lottie.addAnimatorListener(object :
Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
}
override fun onAnimationCancel(animation: Animator?) {
}
override fun onAnimationRepeat(animation: Animator?) {
}
})