Thursday, April 16, 2015

Set more than one animation on a view programatically in android

For this you can use AnimatorSet class of android


This class plays a set of Animator objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.


There are two different approaches to adding animations to a AnimatorSet: either the playTogether() or playSequentially() methods can be called to add a set of animations all at once, or the play(Animator) can be used in conjunction with methods in the Builder class to add animations one by one.

It is possible to set up a AnimatorSet with circular dependencies between its animations. For example, an animation a1 could be set up to start before animation a2, a2 before a3, and a3 before a1. The results of this configuration are undefined, but will typically result in none of the affected animations being played. Because of this (and because circular dependencies do not make logical sense anyway), circular dependencies should be avoided, and the dependency flow of animations should only be in one direction.

For example setting 3 animation on a view at same time:

final AnimatorSet mAnimatorSet = new AnimatorSet();
mAnimatorSet.playTogether(
               ObjectAnimator.ofFloat(target_view,"scaleX",1,0.9f,0.9f,1.1f,1.1f,1),
               ObjectAnimator.ofFloat(target_view,"scaleY",1,0.9f,0.9f,1.1f,1.1f,1),
               ObjectAnimator.ofFloat(target_view,"rotation",0 ,-3 , -3, 3, -3, 3, -3,3,-3,3,-3,0)
       );
mAnimatorSet.setDuration(2000);
mAnimatorSet.start();
mAnimatorSet.addListener(new AnimatorListener()
{


@Override
public void onAnimationEnd(Animator animation)
{


}

@Override
public void onAnimationStart(Animator animation)
{


}

@Override
public void onAnimationCancel(Animator animation)
{


}

@Override
public void onAnimationRepeat(Animator animation)
{


}

});

0 comments:

Post a Comment

Don't lose faith when you see others receive answers to their prayers

An elephant and a dog became pregnant at same time. Three months down the line the dog gave birth to six puppies. Six months later the dog...

 

G-Expo Template by Ipietoon Cute Blog Design