从某一帧循环 Lottie 动画

Ani*_*thy 2 android android-animation lottie

我正在尝试在某些帧之间循环动画,但我根本看不到动画,如果删除代码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}")
                }
Run Code Online (Sandbox Code Playgroud)

和布局文件:

<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"/>
Run Code Online (Sandbox Code Playgroud)

我尝试添加app:lottie_rawRes="@raw/my_animation"上面的布局,但这没有改变任何东西。

Ani*_*thy 7

因此,尽管我不喜欢我正在使用的方法android.animation.Animatorandroid.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?) {
            }
        })
    }
Run Code Online (Sandbox Code Playgroud)

app:lottie_loop="true"并从布局中删除