|
import android.app.Activity; |
|
import android.os.Bundle; |
|
import android.view.MotionEvent; |
|
import android.view.View; |
|
import android.view.animation.DecelerateInterpolator; |
|
import android.view.animation.OvershootInterpolator; |
|
import android.widget.Button; |
|
|
|
/** |
|
* This app shows a simple application of anticipation and follow-through techniques as |
|
* the button animates into its pressed state and animates back out of it, overshooting |
|
* end state before resolving. |
|
* |
|
* Watch the associated video for this demo on the DevBytes channel of developer.android.com |
|
* or on the DevBytes playlist in the androiddevelopers channel on YouTube at |
|
* https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_XOgcRukSoKKjewFJZrKV0. |
|
*/ |
|
public class LiveButton extends Activity { |
|
|
|
DecelerateInterpolator sDecelerator = new DecelerateInterpolator(); |
|
OvershootInterpolator sOvershooter = new OvershootInterpolator(10f); |
|
|
|
@Override |
|
protected void onCreate(Bundle savedInstanceState) { |
|
super.onCreate(savedInstanceState); |
|
setContentView(R.layout.activity_overshoot); |
|
|
|
final Button clickMeButton = (Button) findViewById(R.id.clickMe); |
|
clickMeButton.animate().setDuration(200); |
|
|
|
clickMeButton.setOnTouchListener(new View.OnTouchListener() { |
|
|
|
@Override |
|
public boolean onTouch(View arg0, MotionEvent arg1) { |
|
if (arg1.getAction() == MotionEvent.ACTION_DOWN) { |
|
clickMeButton.animate().setInterpolator(sDecelerator). |
|
scaleX(.7f).scaleY(.7f); |
|
} else if (arg1.getAction() == MotionEvent.ACTION_UP) { |
|
clickMeButton.animate().setInterpolator(sOvershooter). |
|
scaleX(1f).scaleY(1f); |
|
} |
|
return false; |
|
} |
|
}); |
|
|
|
} |
|
} |
It's really cool animation, thank you.