Could anyone tell me the difference between the two methods getAnimatedValue()
and getAnimatedFraction()
used in android ValueAnimator
?
Asked
Active
Viewed 4,296 times
4

Bowdzone
- 3,827
- 11
- 39
- 52

Donny Dominic
- 144
- 1
- 15
1 Answers
8
Did you mean getAnimatedValue() and getAnimatedFraction()?
getAnimatedValue() returns the current value for the variable you are animating.
getAnimatedFraction() returns the value that is used for animating (it always goes from 0.0 to 1.0 basically, and the linearity of it is set by the interpolator). The animatedValue is determined through this by multiplication.
Say you want to linearly animate from 0 to 100 in 10 seconds. On the 9th second, animatedFraction is 0.9f and the animatedValue is 100*0.9f = 90.

Tarps
- 1,928
- 1
- 11
- 27
-
thanks @Travo, yes its getAnimatedValue()instead of getValueAnimator(). and thanks for that example. I used getAnimatedValue() but it was returning an Object, and when I used getAnimatedFraction() it was returning float datatype directly . Why are they having different datatypes.? Because of this i was unable to cast an object to float in the case of **getAnimatedValue()** – Donny Dominic Nov 13 '15 at 09:53
-
1Hey! The getAnimatedValue() does not know about its class type (except that it has to be extending Object). You have to cast it to what it is supposed to be manually. If you know you are animating float, you have to cast it into float: `float opacity = (float) animation.getAnimatedValue();` – Tarps Nov 13 '15 at 09:55
-
Actuallly i had created a class of my own were i am extending **valueAnimator** in which i tried to cast the value to float but i was unable cast the value from getAnimatedValue(). And here above the "animator" object is of which type ? – Donny Dominic Nov 13 '15 at 10:04
-
1Mhh. Here's how I initiated my float animator, which returns an Object that is castable into Float from getAnimatedValue(); `ValueAnimator backgroundAlphaAnimator = ValueAnimator.ofFloat(1f, 0f);` To be honest, I am not so sure what you are asking right now. – Tarps Nov 13 '15 at 10:13
-
kkI will elaborate it.This is how I tried to cast the Value .... .class AnimationSample extends **valueAnimator** { ... float particle=(float) getAnimatedValue();// //showing "Unable to cast from // object to float ...} – Donny Dominic Nov 13 '15 at 10:23
-
You might need to cast it into Float (not the primitive type float). Try `Float particle = (Float) getAnimatedValue();` – Tarps Nov 13 '15 at 10:52
-
Hey thanks ! Now working for me!! Thanks a lot!! :-) – Donny Dominic Nov 13 '15 at 11:06