Skip to content

Instantly share code, notes, and snippets.

@Qamar4P
Last active July 5, 2017 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qamar4P/431bacc3adcb2826c3a8d991bd567e8a to your computer and use it in GitHub Desktop.
Save Qamar4P/431bacc3adcb2826c3a8d991bd567e8a to your computer and use it in GitHub Desktop.
Zoom and bounce twice any number of views in Android
package com.qamar4p.animationexample;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Qamar on 7/5/2017.
*/
public class ZoomBouncingAnimation {
private final View[] mViews;
private final AnimatorSet animatorSet;
public ZoomBouncingAnimation(View... views){
if(views == null || views.length ==0) throw new RuntimeException("Null view error");
mViews = views;
animatorSet = animScale(150,1,1.4f,new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation) {
animScale(150,1.4f, 1f,new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation) {
animScale(180, 1f, 1.3f,new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation) {
animScale(180, 1.3f, 1f,null).start();
}
}).start();;
}
}).start();;
}
});
}
private AnimatorSet animScale(final int duration, final float initialScale, final float lastScale, AnimatorListenerAdapter listenerAdapter) {
List<Animator> animators = new ArrayList<>();
for (View view : mViews) {
animators.add(ObjectAnimator.ofFloat(view,"scaleX", initialScale, lastScale));
animators.add(ObjectAnimator.ofFloat(view,"scaleY", initialScale, lastScale));
}
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animators);
animatorSet.setDuration(duration);
if (listenerAdapter != null) {
animatorSet.addListener(listenerAdapter);
}
return animatorSet;
}
public void play(){
animatorSet.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment