Skip to content

Instantly share code, notes, and snippets.

@m7mdra
Last active December 19, 2017 09:44
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 m7mdra/8d244870777c3b8b03d1290dc5caa38d to your computer and use it in GitHub Desktop.
Save m7mdra/8d244870777c3b8b03d1290dc5caa38d to your computer and use it in GitHub Desktop.
Applies Spring animation to a given view using physics animation API
package comtas.com.zoolvibs.helper;
import android.support.animation.DynamicAnimation;
import android.support.animation.SpringAnimation;
import android.view.View;
/**
* Created by m7mdra on 08/10/17.
*/
public final class SpringAnimator {
public static void animate(final View view) {
view.setEnabled(false);
SpringAnimation startSpringX = new SpringAnimation(view, DynamicAnimation.SCALE_X, 0.90f);
SpringAnimation startSpringY = new SpringAnimation(view, DynamicAnimation.SCALE_Y, 0.90f);
SpringAnimation endSpringX = new SpringAnimation(view, DynamicAnimation.SCALE_X , 1f);
SpringAnimation endSpringY = new SpringAnimation(view, DynamicAnimation.SCALE_Y , 1f);
startSpringX.addEndListener((animation, canceled, value, velocity) -> endSpringX.start());
startSpringY.addEndListener(((animation, canceled, value, velocity) -> endSpringY.start()));
endSpringY.addEndListener(((animation, canceled, value, velocity) -> view.setEnabled(true)));
endSpringX.addEndListener(((animation, canceled, value, velocity) -> view.setEnabled(true)));
startSpringX.start();
startSpringY.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment