create Circular Hide Animator - Android android.animation

Android examples for android.animation:Animator

Description

create Circular Hide Animator

Demo Code


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

import android.annotation.TargetApi;
import android.os.Build;

import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewAnimationUtils;

public class Main {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static Animator createCircularHideAnimator(final View view,
            @Nullable Animator.AnimatorListener listener) {
        if (view.getWindowToken() == null
                || view.getVisibility() == View.INVISIBLE)
            return null;

        // get the center for the clipping circle
        int cx = (view.getLeft() + view.getRight()) / 2;
        int cy = (view.getTop() + view.getBottom()) / 2;

        // get the initial radius for the clipping circle
        int initialRadius = view.getWidth();

        // create the animation (the final radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx,
                cy, initialRadius, 0);/*from w w  w  .j  a  v a2 s . c  o  m*/

        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });

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

Related Tutorials