hide a view with Animation - Android Animation

Android examples for Animation:Animation to Hide

Description

hide a view with Animation

Demo Code

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.os.Build;
import android.view.View;
import android.view.ViewAnimationUtils;

public class Main {
  public static boolean hide(final View p_view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      try {//from w w  w. j  a  v  a 2 s .c o  m
        // get the center for the clipping circle
        int cx = p_view.getWidth() / 2;
        int cy = p_view.getHeight() / 2;

        // get the initial radius for the clipping circle
        float initialRadius = (float) Math.hypot(cx, cy);

        // create the animation (the final radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(p_view, cx, cy, initialRadius, 0);

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            p_view.setVisibility(View.INVISIBLE);
          }
        });

        // start the animation
        anim.start();
      } catch (Exception e) {
        return false;
      }
      return true;
    } else {
      return false;
    }

  }
}

Related Tutorials