Wie setze ich verschiedene Wiederholungswerte (0 gegen Infinite) für verschiedene Ebenen in Lottie Android ein?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie setze ich verschiedene Wiederholungswerte (0 gegen Infinite) für verschiedene Ebenen in Lottie Android ein?

by Anonymous » 10 Apr 2025, 04:09

Ich arbeite mit einer komplexen Lottie -Animation in Android (Kotlin), in der ich: < /p>
  • Einmal einige Schichten abspielen muss (repepcount = 0) < /p>
    < /li>
    andere Layers loop infinpinit (prepectCount = lottTiediewable). /> < /li>
    Die Sichtbarkeit der Steuerschicht dynamisch < /p>

    Code: Select all

    private fun updateValues(modelValue: ModelValue) {
    isAnimationComplete = false
    with(binding.viewAnimation) {
    // 1. Full cleanup of previous state
    cancelAnimation()
    removeAllAnimatorListeners()
    removeAllUpdateListeners()
    progress = 0f
    
    // 3. Update dynamic parts
    updateStatus(modelValue) // Shows/hides layers
    
    // 4. Configure initial play
    repeatCount = 0
    repeatMode = LottieDrawable.RESTART
    
    // 5. Use composition listener to ensure proper setup
    addLottieOnCompositionLoadedListener {
    
    addAnimatorListener(object : Animator.AnimatorListener {
    override fun onAnimationStart(animation: Animator) {
    DevLog.d("LottieDebug", "Initial animation started")
    }
    
    override fun onAnimationEnd(animation: Animator) {
    removeAnimatorListener(this)
    
    // 6. Post to main thread with proper sequencing
    post {
    // Update app state
    isAnimationComplete = true
    previousModel = modelValue
    updateStatusesAnotherLayer(modelValue) // Shows/hides layers
    
    cancelAnimation()
    progress = 0f
    repeatCount = LottieDrawable.INFINITE
    repeatMode = LottieDrawable.RESTART
    
    // 9. Start with frame delay
    postOnAnimation {
    playAnimation()
    }
    }
    }
    
    override fun onAnimationCancel(animation: Animator) {}
    override fun onAnimationRepeat(animation: Animator) {}
    })
    
    // Start initial animation
    playAnimation()
    }
    }
    }
    
Wie diese Ebene ausblenden/anzeigen Ich mache
binding.viewAnimation.addValueCallback(
KeyPath("layer_1"),
LottieProperty.TRANSFORM_OPACITY
) { 0 }

binding.viewAnimation.addValueCallback(
KeyPath("layer_2"),
LottieProperty.TRANSFORM_OPACITY
) { 100 }
< /code>
Problem:
Die unendliche Schleife (repepcount = unendlich) funktioniert nach Abschluss der ersten Animation nicht für bestimmte Ebenen.>

Top