hide View With Animation - Android User Interface

Android examples for User Interface:View Hide Show

Description

hide View With Animation

Demo Code


//package com.java2s;
import android.app.Activity;

import android.support.annotation.AnimRes;

import android.view.View;

import android.view.animation.AnimationUtils;

public class Main {
    public static void hideViewWithAnim(View view, @AnimRes int anim,
            int delay) {
        hideViewWithAnim(view, anim, View.INVISIBLE, 0);
    }/*w  w w.j  av  a2  s  .c om*/

    public static void hideViewWithAnim(final View view,
            @AnimRes 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