show View With Animation in UI thread - Android android.view.animation

Android examples for android.view.animation:Show Animation

Description

show View With Animation in UI thread

Demo Code

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

public class Main {

  public static void showViewWithAnim(final View view, final int anim, final int delay) {
    new Thread(new Runnable() {
      @Override//from ww w  .  j  a  va2s  . c om
      public void run() {
        sleep(delay);

        ((Activity) view.getContext()).runOnUiThread(new Runnable() {
          @Override
          public void run() {
            view.setVisibility(View.VISIBLE);
            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