Last active
December 19, 2017 09:44
-
-
Save m7mdra/8d244870777c3b8b03d1290dc5caa38d to your computer and use it in GitHub Desktop.
Applies Spring animation to a given view using physics animation API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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