animation that hides view in a circular shrinking animation - Android Animation

Android examples for Animation:Animation to Hide

Description

animation that hides view in a circular shrinking animation

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;

import android.view.View;
import android.view.ViewAnimationUtils;

public class Main {
    private static int CENTER_X_INDEX = 0;
    private static int CENTER_Y_INDEX = 1;

    public static void exitReveal(final View view) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            Integer[] centerXcenterYradius = getCenterXcenterY(view);
            int cx = centerXcenterYradius[CENTER_X_INDEX];
            int cy = centerXcenterYradius[CENTER_Y_INDEX];
            int initRadius = view.getWidth() / 2;

            Animator anim = ViewAnimationUtils.createCircularReveal(view,
                    cx, cy, initRadius, 0);

            anim.addListener(new AnimatorListenerAdapter() {
                @Override/*from   w w  w  . j ava2  s  .  c o m*/
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.setVisibility(View.INVISIBLE);
                }
            });

            anim.start();
        } else {
            view.setVisibility(View.INVISIBLE);
        }
    }

    private static Integer[] getCenterXcenterY(View view) {
        Integer[] result = new Integer[2];

        // get the center for the clipping circle
        result[CENTER_X_INDEX] = view.getMeasuredWidth() / 2;
        result[CENTER_Y_INDEX] = view.getMeasuredHeight() / 2;
        return result;
    }
}

Related Tutorials