Android examples for Animation:Fade Animation
Create fade Animation
//package com.java2s; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; public class Main { public static void fadeAnimation(final View view, final float fromAlpha, final float toAlpha, long duration, final Runnable callback) { Animation anim = new AlphaAnimation(fromAlpha, toAlpha); anim.setDuration(duration);//w w w .j a v a 2 s .c o m anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.setAlpha(toAlpha); if (toAlpha > 0) view.setVisibility(View.VISIBLE); else view.setVisibility(View.GONE); if (callback != null) callback.run(); } @Override public void onAnimationRepeat(Animation animation) { } }); view.setVisibility(View.VISIBLE); view.startAnimation(anim); } }