noties / FillDrawable

Apache License 2.0
108 stars 20 forks source link

animation speed? #1

Open vnh1991 opened 8 years ago

vnh1991 commented 8 years ago

How to increase the animation speed?

Thanks for this lib

noties commented 8 years ago

Hey!

As long as you can use any animation mechnism, you can configure anything as you wish. In sample I used Handler, but it could be easily achived with, for example, ValueAnimator.

final FillDrawable fillDrawable = ...;
final float fillPercent = 100.F; // the final fill percent to achieve

final ValueAnimator animator = ValueAnimator.ofFloat(0.F, 1.F);
animator.setEvaluator(new FloatEvaluator());
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1500L); // here could be any value
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        final float fraction = animation.getAnimatedFraction();
        fillDrawable.setFillPercent(fillPercent * fraction);
    }
});
animator.start();

You are welcome!

vnh1991 commented 8 years ago

Thankyou for the prompt reply

pellyadolfo commented 4 years ago

Just a comment. It works but the fillPercent should not be % but per unit, e.g. 0.5f

noties commented 4 years ago

You are right @pellyadolfo , thanks for bringing this up 👍

Use values in range 0.0-1.0F to represent 0-100% progress (with 1.0F = 100%, 0.5F = 50%, etc)