30

I am using animators (ObjectAnimator) to animate few properties (scale, rotate) of a view.

Target view is animating properly when ObjectAnimators are set to it.

But there is an added requirement to get view to the original position (reset) after a while.

I tried to cancel() the animator but it only cancels the animation and doesn't reset the view.

Possible solution : creating another animator that does just opposite of the initial animator.

Is there any other way to reset it ?

Napolean
  • 3,988
  • 2
  • 24
  • 31
  • does it need to reset in the same animation? like fadein-fadeout? – pskink Jun 16 '15 at 05:45
  • I have set duration to it. once it is completed I want to reset it to its original unanimated state like it was before animation. I need same implementation that occurs with view animation when we have fillEnabled = false. – Napolean Jun 16 '15 at 05:51
  • 1
    try custom interpolator then, something like CycleInterpolator – pskink Jun 16 '15 at 05:53
  • @pskink CycleInterpolator will work in my case with some changes that I need to make with cycles and duration adjustments. Thanks. – Napolean Jun 16 '15 at 06:09
  • that's why i suggested a custom Interpolator... – pskink Jun 16 '15 at 06:13
  • Can you give code sample? How will using CycleInterpolator work except repeating the animation for a specified number of cycles? – Alon Aug 10 '17 at 23:42

4 Answers4

0

See the solution I came up with as I had a similar issue with animations inside views in a recycler view, so I had to find a way to reset them:

Trying to reset values from Property Animator to be used in recycler view

Good news in Android O these will be better supported

Alon
  • 402
  • 4
  • 17
0

I had the Same problem with my views . so I came over this problem with this trick . So We assume we have a view that applying an animate after clicking on it .


          viewLayout.arrow_back.setOnClickListener {arrow ->
            arrow.animate().rotationXBy(50F) // this is a just simple anim not so usefull
                .start()
            arrow.isEnabled = false
        }

I hope it'll Help someone .

Bahador Eslami
  • 350
  • 1
  • 10
-1

Do you mean stop a running animation? If so, call clearAnimation() to remove animations from the views that you called startAnimation(); If what you mean is to reset the view to its original appearance after the animation is over, always setFillAfter(false); to the animations.

Jack Xu
  • 65
  • 6
  • 4
    I mean to reset the view to unanimated position as it was before applying animators. clearAnimation() doesn't work. Also it is PropertyAnimation not usual view animations. – Napolean Jun 16 '15 at 05:49
  • This is the correct solution for resetting an animation. `setFillAfter(false);` did the trick perfectly. – Megaetron Apr 25 '19 at 22:25
-1

I met the same problem, because I animate the view use ViewPropertyAnimator, addView() and removeView() again and again for not creating new view, but a view can be shown once, when you remove the view, you call addview() again, it is no show, but you see the property visibility is visible and animationListener also be called. it is strange.

nima moradi
  • 1,482
  • 16
  • 29
Jamishon
  • 1
  • 4