Android examples for Animation:Shake Animation
shake effect animation
//package com.java2s; import android.view.View; import android.view.animation.CycleInterpolator; import android.view.animation.TranslateAnimation; public class Main { public static final long DEFAULT_ANIMATION_DURATION = 1000; public static void shake(View view, float fromXDelta, float toXDelta, long durationMillis, float cycles) { translate(view, fromXDelta, toXDelta, 0.0f, 0.0f, durationMillis, cycles);//from w w w .j a va 2 s. c o m } public static void shake(View view) { shake(view, 0.0f, 10.0f, DEFAULT_ANIMATION_DURATION, 7); } public static void translate(View view, float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long durationMillis, float cycles) { TranslateAnimation translateAnimation = new TranslateAnimation( fromXDelta, toXDelta, fromYDelta, toYDelta); translateAnimation.setDuration(durationMillis); if (cycles > 0.0) { translateAnimation .setInterpolator(new CycleInterpolator(cycles)); } view.startAnimation(translateAnimation); } }