Reputation: 97
animatingview=0;
ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f, 1f, 0.2f, 1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(600);
final ConstraintLayout s=findViewById(R.id.editprofileheadid);
while(animatingview<s.getChildCount()){
s.getChildAt(animatingview).startAnimation(scaleAnimation);
animatingview++;
}
I successfully created the animation for all view in my constraint layout but all the view are animating at the same time, I need all the view to be animated one after another, I tried Sleep but I didn't get that luck
Upvotes: 0
Views: 47
Reputation: 4060
Use setAnimationListener
on your animation to start the next animations in onAnimationEnd
. You'd basically want to do something along the following lines,
animatingview=0;
ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f, 1f, 0.2f, 1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(600);
final ConstraintLayout s=findViewById(R.id.editprofileheadid);
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
if(animatingview<s.getChildCount()){
//Subsequent animations are started here
s.getChildAt(animatingview).startAnimation(scaleAnimation);
animatingview++;
}
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
//First view animation is started here
s.getChildAt(animatingview).startAnimation(scaleAnimation);
Upvotes: 1