Roy Lee
Roy Lee

Reputation: 10842

Gradually increase/decrease animation speed? [Android]

I was working on animated effect on android, I would like to know if there's any other way to gradually increase/decrease the animation speed?

Is it possible to specify like first 3 second rate of change was slow, and the rest goes fast?

Upvotes: 1

Views: 2292

Answers (1)

mach
mach

Reputation: 8395

Use a Interpolator. For your case I would recommend the AccelerateDecelerateInterpolator

Animation anim = AnimationUtils.loadAnimation(this, R.anim.your_animation);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
image.startAnimation(anim);

As for the interpolator, you can build your own!

public class MyInterpolator extends Interpolator {

    public MyInterpolator(int valueCount) {
        super(valueCount);
    }

    public float getInterpolation (float input) {
        return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
    }
}

Using Wolfram Alpha you can play with the parameters.

Upvotes: 5

Related Questions