Android examples for android.view.animation:Effect Animation
shake View
import android.animation.Animator; import android.animation.Animator.AnimatorListener; import android.animation.ObjectAnimator; import android.view.View; public class Main { public static void shakeView(final View view) { ObjectAnimator physX = ObjectAnimator.ofFloat(view, "translationX", -12f, 12f); physX.setDuration(50);//from w w w .j a va 2 s .c o m physX.setRepeatCount(10); physX.setRepeatMode(ObjectAnimator.RESTART); physX.addListener(new AnimatorListener() { @Override public void onAnimationEnd(Animator animation) { view.animate().translationX(0f).setDuration(10); } @Override public void onAnimationCancel(Animator arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animator arg0) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animator arg0) { // TODO Auto-generated method stub } }); physX.start(); } }