push View ScaleAnimation - Android android.view.animation

Android examples for android.view.animation:Scale Animation

Description

push View ScaleAnimation

Demo Code

import android.view.MotionEvent;
import android.view.View;
import android.view.animation.ScaleAnimation;

public class Main{

    /**/*from w w w  . j a  va  2 s .c  om*/
     * Animation Duration
     */
    private final static int DURATION = 100;
    /**
     * push View ScaleAnimation
     *
     * @param targetView TargetView
     * @param action     MotionEventAction
     * @param scaleX
     * @param scaleY
     */
    private static void pushScale(View targetView, int action,
            float scaleX, float scaleY) {
        if (action == MotionEvent.ACTION_DOWN) {
            // Touch Down
            ScaleAnimation anim = new ScaleAnimation(1.0f, scaleX, 1.0f,
                    scaleY, targetView.getWidth() / 2,
                    targetView.getHeight() / 2);
            anim.setDuration(DURATION);
            anim.setFillEnabled(true);
            anim.setFillAfter(true);
            targetView.startAnimation(anim);
        } else if (action == MotionEvent.ACTION_CANCEL
                || action == MotionEvent.ACTION_UP) {
            // Touch Up
            ScaleAnimation anim = new ScaleAnimation(scaleX, 1.0f, scaleY,
                    1.0f, targetView.getWidth() / 2,
                    targetView.getHeight() / 2);
            anim.setDuration(DURATION);
            anim.setFillEnabled(true);
            anim.setFillAfter(true);
            targetView.startAnimation(anim);
        }
    }

}

Related Tutorials