hide View horizontally - Android Animation

Android examples for Animation:Slide Animation

Description

hide View horizontally

Demo Code


import android.animation.Animator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.Interpolator;

public class Main {
  private static final Interpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new FastOutSlowInInterpolator();

  public static void hideViewX(final View view, boolean animToRight) {
    ViewPropertyAnimator animator = view.animate().translationX((animToRight) ? view.getWidth() : view.getWidth() * -1)
        .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).setDuration(200);

    animator.setListener(new Animator.AnimatorListener() {
      @Override//w ww .  j a  v  a2 s  .  c om
      public void onAnimationStart(Animator animator) {
      }

      @Override
      public void onAnimationEnd(Animator animator) {
        view.setVisibility(View.GONE);
        view.setX(0);
      }

      @Override
      public void onAnimationCancel(Animator animator) {
      }

      @Override
      public void onAnimationRepeat(Animator animator) {
      }
    });
    animator.start();
  }
}

Related Tutorials