Create fade In Out Animation - Android Animation

Android examples for Animation:Fade Animation

Description

Create fade In Out Animation

Demo Code


//package com.java2s;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

public class Main {
    public static Animation fadeInOutAnimation(final View view,
            final float fromAlpha, final float toAlpha, long duration) {

        view.clearAnimation();/*from   w  ww .jav a2 s. c om*/
        AlphaAnimation fadein = new AlphaAnimation(fromAlpha, toAlpha);
        fadein.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                view.setAlpha(fromAlpha);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                view.setAlpha(toAlpha);
            }
        });
        fadein.setDuration(duration);

        return fadein;
    }
}

Related Tutorials