Created
July 23, 2013 07:32
-
-
Save DanielGrech/6060507 to your computer and use it in GitHub Desktop.
Creates a 'bouncy effect' on the passed view (code from DevBytes episode - http://www.youtube.com/watch?v=uQ7PTe7QMQM) Note this version depends on nineoldandroids
This file contains hidden or 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
/** | |
* Applies a touch listener to <code>v</code> which causes the view to 'expand and contract' | |
* based on it's touch state | |
* | |
* @param v | |
* The view to apply the touch listener too | |
* @param bounceTension | |
* The tension (bounce back) to apply when the user lifts their finger from the view | |
*/ | |
public static void applyBounceTouchListener(final View v, final int bounceTension) { | |
v.setOnTouchListener(new View.OnTouchListener() { | |
private final DecelerateInterpolator mDecelerateInterpolator | |
= new DecelerateInterpolator(); | |
private final OvershootInterpolator mOvershootInterpolator | |
= new OvershootInterpolator(bounceTension); | |
@Override | |
public boolean onTouch(View v, MotionEvent event) { | |
if (event.getAction() == MotionEvent.ACTION_DOWN) { | |
ViewPropertyAnimator.animate(v) | |
.setInterpolator(mDecelerateInterpolator) | |
.scaleY(0.85f).scaleX(0.85f).setDuration(200); | |
} else if (event.getAction() == MotionEvent.ACTION_UP) { | |
ViewPropertyAnimator.animate(v) | |
.setInterpolator(mOvershootInterpolator) | |
.scaleY(1f).scaleX(1f).setDuration(200); | |
} | |
return false; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment