Returns scale target object from its center to both way, until it reaches to given value from given one - Android Animation

Android examples for Animation:Scale Animation

Description

Returns scale target object from its center to both way, until it reaches to given value from given one

Demo Code


//package com.java2s;

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

import android.view.animation.Interpolator;
import android.view.animation.ScaleAnimation;

public class Main {
    /**/*w  ww . j a  v  a 2 s  .c  o m*/
     * Returns scale target object from its center to both way, until it reaches
     * to given value from given one
     * 
     * @param from
     *            : Float value to determine animation initial scale for both
     *            coordinates
     * @param to
     *            : Float value to determine animation scale for both
     *            coordinates
     * @param duration
     *            : Animation duration
     */
    public static Animation Scale(float from, float to, int duration) {
        return Scale(from, to, duration, null);
    }

    /**
     * Returns scale target object from its center to both way with
     * interpolation, until it reaches to given value from given one
     * 
     * @param from
     *            : Float value to determine animation initial scale for both
     *            coordinates
     * @param to
     *            : Float value to determine animation scale for both
     *            coordinates
     * @param duration
     *            : Animation duration
     * @param interpolation
     *            : Animation interpolation
     */
    public static Animation Scale(float from, float to, int duration,
            Interpolator interpolation) {
        return Scale(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f, duration, interpolation,
                null);
    }

    /**
     * Returns scale target object from its center to both way with
     * interpolation, until it reaches to given value from given one
     * 
     * @param from
     *            : Float value to determine animation initial scale for both
     *            coordinates
     * @param to
     *            : Float value to determine animation scale for both
     *            coordinates
     * @param duration
     *            : Animation duration
     * @param interpolation
     *            : Animation interpolation
     * @param listener
     *            : Animation listener to send callback
     */
    public static Animation Scale(float from, float to, int duration,
            Interpolator interpolation, AnimationListener listener) {
        return Scale(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f, duration, interpolation,
                listener);
    }

    /**
     * Returns scale target object with interpolation up to given X-Y pairs and
     * dispatch callback with AnimationListener
     * 
     * @param fromX
     *            : Float value to determine animation initial scale for X
     *            coordinate
     * @param toX
     *            : Float value to determine animation scale for X coordinate
     * @param fromY
     *            : Float value to determine animation initial scale for Y
     *            coordinate
     * @param toY
     *            : Float value to determine animation scale for Y coordinate
     * @param pivotXType
     *            : Type to determine whether target should scale up to itself
     *            or parent and so on
     * @param pivotXValue
     *            : Float value to determine target needs to start scaling from
     *            X coordinate
     * @param pivotYType
     *            : Type to determine whether target should scale up to itself
     *            or parent and so on
     * @param pivotYValue
     *            : Float value to determine target needs to start scaling from
     *            Y coordinate
     * @param duration
     *            : Animation duration
     * @param interpolation
     *            : Animation interpolation
     * @param listener
     *            : Animation listener to send callback
     */
    public static Animation Scale(float fromX, float toX, float fromY,
            float toY, int pivotXType, float pivotXValue, int pivotYType,
            float pivotYValue, int duration, Interpolator interpolation,
            AnimationListener listener) {
        ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY,
                toY, pivotXType, pivotXValue, pivotYType, pivotYValue);
        animation.setDuration(duration);

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

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

        return animation;
    }
}

Related Tutorials