Java tutorial
//package com.java2s; //License from project: Open Source License import android.view.View; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; public class Main { public static void startAnimation(View target, int aniResId) { startAnimation(target, aniResId, null); } public static void startAnimation(View target, int aniResId, int duration) { if (target == null) return; Animation animation = AnimationUtils.loadAnimation(target.getContext(), aniResId); if (animation != null) { animation.setDuration(duration); target.startAnimation(animation); } } public static void startAnimation(View target, int aniResId, AnimationListener listener) { if (target == null) return; Animation animation = AnimationUtils.loadAnimation(target.getContext(), aniResId); if (animation != null) { if (listener != null) { animation.setAnimationListener(listener); } target.startAnimation(animation); } } }