hide View With Animation - Android android.view.animation

Android examples for android.view.animation:Hide Animation

Description

hide View With Animation

Demo Code

import android.app.Activity;
import android.view.View;
import android.view.animation.AnimationUtils;

public class Main {

  public static void hideViewWithAnim(View view, int anim, int delay) {
    hideViewWithAnim(view, anim, View.INVISIBLE, 0);
  }/*www  .  j  ava 2 s  .  c om*/

  public static void hideViewWithAnim(final View view, final int anim, final int visibility, final int delay) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        sleep(delay);

        ((Activity) view.getContext()).runOnUiThread(new Runnable() {
          @Override
          public void run() {
            view.setVisibility(visibility);
            view.startAnimation(AnimationUtils.loadAnimation(view.getContext(), anim));

          }
        });
      }
    }).start();
  }

  private static void sleep(int millis) {
    try {
      Thread.sleep(millis);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

}

Related Tutorials