Android: Why do object animators keep their initial value?

I have a mix of animations working in different scenarios. As an example:

I have fade-in and fade-out animations in a small circular bitmap. On ACTION_DOWNshould start fade-in and on ACTION_UP, when the ends of the attenuation end , the attenuation must be performed. BUT, if the user raises his finger in front of the ends of the attenuation, he should stop there ( fadein.cancel()), the fade-out should start with the THAT alpha value. I don’t want a new animator of objects every time, I defined such an animator in the constructor

    fadein = Objectanimator.ofFloat(bitmap, "alpha", 1.0f);
    fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 0.0f);

What happens if I create a problem, as mentioned (quickly typing my finger), the fadeout animator will pick an alpha value in which the fade-in value will stop and it will be RETAIN. That is, the 2nd time, he will NOT pick up a new alpha! Why is this? What is the workaround? Create new objects every time?

+4
source share
1 answer

ObjectAnimatorthe class changes the attributes of the view, so it updates the view property using the setter method of the Object property (according to the official Android Guide ).

So, when the animation fadeinstarts, the alpha value is constantly changing, and when it fadein.cancel()is executed, the alpha value of the View stops updating. Say this value X.

, fadeOut, X 0.0f.

?

fadeOut

fadeOut = Objectanimator.ofFloat(bitmap, "alpha", 1.0f, 0.0f);
+3

All Articles