hide View with AnimationListener - Android android.view.animation

Android examples for android.view.animation:Hide Animation

Description

hide View with AnimationListener

Demo Code

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;

public class Main {

  public static void hideView(Context context, final View view, int animId) {
    if (view == null)
      return;//w w w .j  a  v  a  2 s  .com
    if (view.getVisibility() == View.GONE)
      return;
    view.clearAnimation();
    // view.setVisibility(View.GONE);
    Animation localAnim = AnimationUtils.loadAnimation(context, animId);
    localAnim.setAnimationListener(new AnimationListener() {

      @Override
      public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub
      }

      @Override
      public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
      }

      @Override
      public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        view.setVisibility(View.GONE);
      }
    });
    view.startAnimation(localAnim);
  }

}

Related Tutorials