Is it possible to get animated value from ValueAnimator
without starting the animation? I do have start and target color.
I have a PageTransformer
and I want to set background color based on page position. so I want to change background color as the page slides. (not after the page slides)
Is it possible to use ValueAnimator
without overhead of starting animation?
A simple example of what i want
Lets say start value is 0 and target value is 100. animation duration is 500ms.
When i pass 53ms it should output (53/500)*(100).
Now this is a simple example, how do i do it for a color?
You seem to be writing not exactly about animation, but about interpolation. To get a color value interpolated like you described, you can use ArgbEvaluator
. This is pretty much what animator does internally and you can use that in page sliding animation without any additional animator.
ArgbAnimator evaluator = new ArgbAnimator();
float fraction = 0.53f; // value between 0.0f and 1.0f
int color1 = Color.RED, color2 = Color.GREEN;
int interpolatedColor = evaluator.evaluate(fraction, color1, color2);