Skip to content

Instantly share code, notes, and snippets.

@m7mdra
Last active Dec 19, 2017
Embed
What would you like to do?
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