Android: Why do Object Animators retain the start value?
android, objectanimator
Solution
`ObjectAnimator` class modifies the attributes of the view, so it updates the property of the view using the setter method of the Object property (as per official Android Guide).
So, when `fadein` animation runs, the alpha value is constantly modified, and when `fadein.cancel()` executes, the alpha value of the View stops updating. Let's say this value is `X`.
So, when you start `fadeOut`, it animates from `X` to `0.0f`.
Whats the workaround?
For `fadeOut`, use two values imply a starting and ending values
fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 1.0f, 0.0f);
Problem
I have a mixture of animations running on various scenarios. As an example; I have a fade-in and fade-out animator on a small circle bitmap. On `ACTION_DOWN` the `fade-in` should start and on `ACTION_UP`, when the fade-in ends, fade-out should run. BUT, if the user picks up the finger before the fade-in ends, it should stop right there (`fadein.cancel()`), fade-out should start from THAT alpha value. I dont want a new object animator each time, I defined an animator like this in the constructor ``` fadein = Objectanimator.ofFloat(bitmap, "alpha", 1.0f); fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 0.0f); ``` What happens is, if I produce the issue as mentioned (picking up the finger fast), the fadeout animator will pick up the alpha value where fade-in left off and it'll RETAIN that. That is, 2nd time onwards it'll NOT pick up a new alpha! Why is that? Whats the workaround? Create new objects each time?