Kemix Kemix - 1 year ago 93
Android Question

Android: Stay in state of older animation when start a new animation

I would like to make two type of animation on a single view : a TranslateAnimation and a few moment later a ScaleAnimation. The problem is that when the ScaleAnimation begins the views return to their initial state (before the TranslateAnimation). Is there a way to do what I want ?

Answer Source

You can add a listener to the TranslateAnimation, and when it's done, change the position of the View to the animation's end position.

TranslateAnimation anim = new TranslateAnimation(...);
anim.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) { }
public void onAnimationRepeat(Animation animation) { }
public void onAnimationEnd(Animation animation) {

But I'd suggest actually switching from the old TranslateAnimation/ScaleAnimation type of classes, to the new ViewPropertyAnimator framework ( In the new framework you don't have to change positions like in the above code, and the syntax is much simpler:


you can also use AnimatorSet to create a set of animation to be played together or one after the other.

Further reading:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download