Android examples for android.view.animation:ObjectAnimator
shake View with ObjectAnimator
import android.animation.ObjectAnimator; import android.util.TypedValue; import android.view.View; import android.view.animation.LinearInterpolator; public class Main{ public static void shake(View v) { final float distance = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 4.0f, v.getResources() .getDisplayMetrics()); final ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationX", 0, distance, 0, -distance, 0); animator.setRepeatMode(ObjectAnimator.RESTART); animator.setInterpolator(new LinearInterpolator()); animator.setRepeatCount(4);/*from w ww .j a va2s .c o m*/ animator.setDuration(150); animator.start(); } }