Value & Object Animators - Challenge 1: Animate the title and rating

Hi, I am trying to animate the title follow the implementation of animateBackdrop

Here is my code:

    private fun animateTitle() {
        val finalY = binding.title.y
        val startY = finalY.minus(40)

        binding.title.y = startY

        val animator = ValueAnimator.ofFloat(startY, finalY)

        animator.duration = 1000

        animator.addUpdateListener {
            val animatedValue = it.animatedValue as Float
            binding.title.translationY = animatedValue
        }

        animator.start()
    }

and invoke after animateSummary().

However, I the actual position of the title after the animation is not collect, and I cannot figure out the reason, could anybody tell me the reason why it will moved to the wrong position?

Thanks.

1 Like

Did you follow the instructions & reference the challenge’s repo?

/**

  • Animating single properties with [ObjectAnimator] for a View
  • */
    private fun animateText(view: View) {
    // Init ObjectAnimator using offFloat() static function
    val objectAnimator = ObjectAnimator.ofFloat(
    view, “alpha”, 0f, 1f
    )
    objectAnimator.duration = 1500 // the animation duration
    objectAnimator.start() // start the anim
    }
    }

if (viewModel.shouldAnimate) {
// animate the summary
animateText(binding.title)
animateText(binding.summary)
animateText(binding.ratingValue)
animateText(binding.movieRating)
}

:handshake: If you already fixed it, please close this issue!