Example usage for android.view.animation ScaleAnimation setFillEnabled

List of usage examples for android.view.animation ScaleAnimation setFillEnabled

Introduction

In this page you can find the example usage for android.view.animation ScaleAnimation setFillEnabled.

Prototype

public void setFillEnabled(boolean fillEnabled) 

Source Link

Document

If fillEnabled is true, the animation will apply the value of fillBefore.

Usage

From source file:Main.java

public static void setOnTouchScaleAnimation(View targetView, final float scaleX, final float scaleY) {
    targetView.setOnTouchListener(new View.OnTouchListener() {
        @Override//from   ww w  . j  ava 2  s  .  c o m
        public boolean onTouch(View v, MotionEvent event) {
            final int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN: {
                ScaleAnimation anim = new ScaleAnimation(1.0f, scaleX, 1.0f, scaleY, v.getWidth() / 2,
                        v.getHeight() / 2);
                anim.setDuration(60);
                anim.setFillEnabled(true);
                anim.setFillAfter(true);
                v.startAnimation(anim);
                break;
            }
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP: {
                ScaleAnimation anim = new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, v.getWidth() / 2,
                        v.getHeight() / 2);
                anim.setDuration(100);
                v.startAnimation(anim);
                break;
            }
            }
            return false;
        }
    });
}

From source file:Main.java

/**
 * push View ScaleAnimation/*ww  w. j a  v  a  2 s.  com*/
 *
 * @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);
    }
}

From source file:Main.java

public static void scale(final View view, float fromScale, float toScale, long duration,
        final Runnable whenDone) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0) {
            view.setScaleX(toScale);//from   w w w .  j a  va2s.c om
            view.setScaleY(toScale);
            if (whenDone != null)
                whenDone.run();
        } else {
            ViewPropertyAnimator animation = view.animate().scaleX(toScale).scaleY(toScale)
                    .setDuration(duration);
            if (whenDone != null) {
                animation.setListener(new AnimatorListener() {
                    @Override
                    public void onAnimationCancel(Animator animation) {
                        whenDone.run();
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        whenDone.run();
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                    }

                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                });
            }
            animation.start();
        }
    } else {
        ScaleAnimation scale = new ScaleAnimation(fromScale, toScale, fromScale, toScale,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scale.setDuration(duration);
        scale.setFillEnabled(true);
        scale.setFillBefore(true);
        scale.setFillAfter(true);

        if (whenDone != null) {
            scale.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    whenDone.run();
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                }

            });
        }
        addAnimation(view, scale);
    }
}