apply alpha animation to given view - Android android.view.animation

Android examples for android.view.animation:Color Animation

Description

apply alpha animation to given view

Demo Code

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

public class Main{

    /**/*from  w  w w  .  j a  v a2 s .  com*/
     * apply alpha animation to given view
     * @param view
     * @param from
     * @param to
     * @param duration
     * @param listener animator listener adapter, can be null
     * @return ObjectAnimator
     */
    public static ObjectAnimator fade(View view, float from, float to,
            int duration, AnimatorListenerAdapter listener) {
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", from,
                to);
        alpha.setDuration(duration);

        if (listener != null) {
            alpha.addListener(listener);
        }

        alpha.start();

        return alpha;

    }

}

Related Tutorials