Returns an alpha animation from given opacity to given one - Android Animation

Android examples for Animation:Alpha Fly Animation

Description

Returns an alpha animation from given opacity to given one

Demo Code


//package com.java2s;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import android.view.animation.Interpolator;

public class Main {
    /**/*w w  w. j  ava2  s. co m*/
     * Returns an alpha animation from given opacity to given one
     * 
     * @param from
     *            : Float value to determine opacity at the beginning
     * @param to
     *            : Float value to determine opacity at the end
     * @param duration
     *            : Animation duration
     */
    public static Animation Alpha(float from, float to, int duration) {
        return Alpha(from, to, duration, null);
    }

    /**
     * Returns an alpha animation from given opacity to given one with
     * interpolation, but without callback
     * 
     * @param from
     *            : Float value to determine opacity at the beginning
     * @param to
     *            : Float value to determine opacity at the end
     * @param duration
     *            : Animation duration
     * @param interpolation
     *            : Animation interpolation
     */
    public static Animation Alpha(float from, float to, int duration,
            Interpolator interpolation) {
        return Alpha(from, to, duration, interpolation, null);
    }

    /**
     * Returns an alpha animation on target object from given opacity to given
     * one with interpolation and send callback to listener
     * 
     * @param from
     *            : Float value to determine opacity at the beginning
     * @param to
     *            : Float value to determine opacity at the end
     * @param duration
     *            : Animation duration
     * @param interpolation
     *            : Animation interpolation
     * @param listener
     *            : Animation listener to send callback
     */
    public static Animation Alpha(float from, float to, int duration,
            Interpolator interpolation, AnimationListener listener) {
        AlphaAnimation animation = new AlphaAnimation(from, to);
        animation.setDuration(duration);

        if (interpolation != null)
            animation.setInterpolator(interpolation);

        if (listener != null) {
            animation.setAnimationListener(listener);
        }

        return animation;
    }
}

Related Tutorials