How do I add Listener to ObjectAnimator in Kotlin?

Viewed 1849

I did something like this

val animator = ObjectAnimator.ofFloat(view, "translationY", 350f,0f)
    animator.duration = 500
    animator.startDelay=200
    animator.interpolator =AccelerateDecelerateInterpolator()
    animator.start()

Now I am trying to add listener to this adapter. I have tried this,

animator.addListener(onStart = {view.visibility=View.VISIBLE})

but is not working.

1 Answers

Although your question is not clear, as you are not mentioning what is not working. My guess is that your listener is useless.

You are starting the animator and then adding it which of course will never be invoked.

Change as following:

val animator = ObjectAnimator.ofFloat(view, "translationY", 350f, 0f)
animator.apply {
    duration = 500
    startDelay = 200
    addListener(onStart = {
        view.visibility = View.VISIBLE
    })
    AccelerateDecelerateInterpolator()
    start()
}
Related