Java tutorial
//package com.java2s; //License from project: Apache License import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.TranslateAnimation; public class Main { public static Animation shakeAnimation(int X) { AnimationSet set = new AnimationSet(true); Animation anim1 = getTranslateAnimation(0, -200, 0, 0, 100); anim1.setStartOffset(100); set.addAnimation(anim1); Animation anim2 = getTranslateAnimation(-200, 400, 0, 0, 200); anim2.setStartOffset(300); set.addAnimation(anim2); Animation anim3 = getTranslateAnimation(400, -200, 0, 0, 200); anim3.setStartOffset(500); set.addAnimation(anim3); Animation anim4 = getTranslateAnimation(-200, 0, 0, 0, 100); anim4.setStartOffset(600); set.addAnimation(anim4); set.setFillAfter(true); set.setDuration(640); return set; } public static Animation getTranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long durationMillis) { TranslateAnimation translate = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); translate.setDuration(durationMillis); translate.setFillAfter(true); return translate; } }