我正在尝试在某些帧之间循环播放动画,但是我根本看不到动画,如果我删除了LottieCompositionFactory....addListener
代码并仅使用xml文件,则会显示动画,但是,我想在某些帧之间运行动画:
class OnboardingFragment : Fragment() {
...
...
private var myComposition: LottieComposition? = null
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
LottieCompositionFactory.fromRawRes(context, R.raw.my_animation)
.addListener {
myComposition = it
Log.d(TAG, "Is animation displaying: $myComposition") //does print the LottieComposition
with(lottieAnimation) {
alpha = 0F
visibility = View.VISIBLE
myComposition?.let { it1 -> setComposition(it1) }
repeatCount = ValueAnimator.INFINITE
setMinAndMaxFrame(29, 219)
playAnimation()
}
}
.addFailureListener {
Log.e(TAG, "Error displaying animation: ${it.message}")
}
和布局文件:
<androidx.constraintlayout.widget.ConstraintLayout
...
...
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieAnimation"
android:layout_width="170dp"
android:layout_height="146dp"
android:layout_marginBottom="34dp"
android:scaleType="fitStart"
app:layout_constraintBottom_toTopOf="@+id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topGuide"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
我尝试在上述布局中添加app:lottie_rawRes="@raw/my_animation"
,但没有任何改变。
答案 0 :(得分:0)
因此,即使我不喜欢使用fetch('url', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
body: formData
})
,android.animation.Animator
和android.animation.ValueAnimator
,我还是采用了这种方法:
LottieAnimation
并从布局中删除了 private fun setupAnimation(lottieAnimation: LottieAnimationView) {
lottieAnimation.addAnimatorListener(object : Animator.AnimatorListener {
override fun onAnimationStart(anim: Animator?) {
}
override fun onAnimationEnd(anim: Animator?) {
lottieAnimation.removeAllAnimatorListeners()
lottieAnimation.repeatCount = ValueAnimator.INFINITE
lottieAnimation.setMinAndMaxFrame(25, 147)
lottieAnimation.playAnimation()
}
override fun onAnimationRepeat(anim: Animator?) {
}
override fun onAnimationCancel(anim: Animator?) {
}
})
}