fade To Opacity - Android Animation

Android examples for Animation:Fade Animation

Description

fade To Opacity

Demo Code


//package com.java2s;
import android.animation.FloatEvaluator;
import android.animation.ValueAnimator;
import android.view.View;
import static android.animation.ValueAnimator.ofObject;

public class Main {
    public static void fadeToOpacity(final View view, float toValue,
            long duration) {
        fadeToOpacity(view, view.getAlpha(), toValue, duration);
    }/*from w ww .j  a va2 s  .c  om*/

    public static void fadeToOpacity(final View view, float fromValue,
            float toValue, long duration) {
        ValueAnimator valueAnimator = ofObject(new FloatEvaluator(),
                fromValue, toValue);
        valueAnimator
                .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animator) {
                        view.setAlpha((float) animator.getAnimatedValue());
                    }
                });
        valueAnimator.setDuration(duration);
        valueAnimator.start();
    }
}

Related Tutorials