Android examples for android.view.animation:Fade Animation
start Fade Out Animation
import android.annotation.SuppressLint; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; public class Main { public static void startFadeOutAnimation(final View view, long duration) { startAnimation(view, getFadeInOutAnimation(view, 1, 0, duration)); }/* ww w. j a va2 s . co m*/ @SuppressLint("NewApi") public static AlphaAnimation getFadeInOutAnimation(final View view, final float fromAlpha, final float toAlpha, long duration) { AlphaAnimation fadeInOut = new AlphaAnimation(fromAlpha, toAlpha); fadeInOut.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { view.setAlpha(fromAlpha); // setAlpha() since from API level 11, Android 3.0 } public void onAnimationEnd(Animation animation) { view.setAlpha(toAlpha); // setAlpha() since from API level 11, Android 3.0 } public void onAnimationRepeat(Animation animation) { } }); fadeInOut.setDuration(duration); return fadeInOut; } public static void startAnimation(View view, Animation anim) { view.clearAnimation(); view.startAnimation(anim); // view.invalidate(); } }