circular Hide View Animation - Android User Interface

Android examples for User Interface:View Hide Show

Description

circular Hide View Animation

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 {
    public static void circularHide(final View view,
            Animator.AnimatorListener listener) {
        Animator anim = createCircularHideAnimator(view, listener);
        if (anim != null)
            anim.start();// ww w .  j  a v  a  2s . c om
    }

    @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);

        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