scale view - Android android.view.animation

Android examples for android.view.animation:Scale Animation

Description

scale 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{

    /**// w ww.ja  v  a 2  s .c  o m
     * scale view
     * @param view
     * @param from
     * @param to
     * @param pivotX
     * @param pivotY
     * @param duration
     * @param listener listener animator listener adapter, can be null
     */
    public static void scale(View view, float from, float to, float pivotX,
            float pivotY, int duration, AnimatorListenerAdapter listener) {
        view.setPivotX(pivotX);
        view.setPivotY(pivotY);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX",
                from, to);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY",
                from, to);

        scaleX.setDuration(duration);
        scaleY.setDuration(duration);

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

        scaleX.start();
        scaleY.start();

    }
    /**
     * scale view
     * @param view
     * @param from
     * @param to
     * @param duration
     * @param listener listener animator listener adapter, can be null
     */
    public static void scale(View view, float from, float to, int duration,
            AnimatorListenerAdapter listener) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX",
                from, to);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY",
                from, to);

        scaleX.setDuration(duration);
        scaleY.setDuration(duration);

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

        scaleX.start();
        scaleY.start();

    }

}

Related Tutorials