Skip to content

Instantly share code, notes, and snippets.

@n1lesh
Last active June 22, 2017 10:28
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 n1lesh/209516b3f7a9409bdb2bb9cff64c1aac to your computer and use it in GitHub Desktop.
Save n1lesh/209516b3f7a9409bdb2bb9cff64c1aac to your computer and use it in GitHub Desktop.
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