get Fade In Out Animation - Android android.view.animation

Android examples for android.view.animation:Fade Animation

Description

get Fade In Out Animation

Demo Code

import android.annotation.SuppressLint;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

public class Main {

  @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
      }//from  w  ww  .j  av a  2 s  .c  o  m

      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;
  }

}

Related Tutorials