Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting spring like effect on Android Buttons with ViewPropertyAnimator
final Button button = (Button) findViewById(R.id.v);
final ViewPropertyAnimator animator = button.animate();
animator.setDuration(200);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button.setEnabled(false);
animator.scaleXBy(-0.06f)
.scaleYBy(-0.06f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animator.scaleXBy(0.06f)
.scaleYBy(0.06f)
.setListener(null)
.withEndAction(new Runnable() {
@Override
public void run() {
button.setEnabled(true);
}
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment