Fly a view out by moving it vertically off the bottom of the screen. - Android User Interface

Android examples for User Interface:Window

Description

Fly a view out by moving it vertically off the bottom of the screen.

Demo Code


import java.util.List;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.Interpolator;

public class Main {
  private static Interpolator sDecelerateQuintInterpolator;
  /**/*from  ww w .  ja v  a 2  s.c  o  m*/
   * Duration of an individual animation when the children of the grid are laid
   * out again. This is measured in milliseconds.
   */
  private static int sAnimationDuration = 450;

  /**
   * Fly a view out by moving it vertically off the bottom of the screen.
   */
  public static void addFlyOutAnimators(List<Animator> animators, final View view, int startTranslation,
      int endTranslation, int animationDelay) {
    addYTranslationAnimators(animators, view, startTranslation, endTranslation, animationDelay, null);
  }

  public static void addFlyOutAnimators(List<Animator> animators, final View view, int startTranslation,
      int endTranslation) {
    addFlyOutAnimators(animators, view, startTranslation, endTranslation, 0 /* animation delay */);
  }

  /**
   * Add animations to translate a view's Y-translation. {@link AnimatorListener}
   * can be null.
   */
  private static void addYTranslationAnimators(List<Animator> animators, final View view, int startTranslation,
      final int endTranslation, int animationDelay, AnimatorListener listener) {
    // We used to skip the animation if startTranslation == endTranslation,
    // but to add a recycle view listener, we need at least one animation
    view.setTranslationY(startTranslation);
    final ObjectAnimator translateAnimatorY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, startTranslation,
        endTranslation);
    translateAnimatorY.setInterpolator(sDecelerateQuintInterpolator);
    translateAnimatorY.setDuration(sAnimationDuration);
    translateAnimatorY.setStartDelay(animationDelay);

    if (listener != null) {
      translateAnimatorY.addListener(listener);
    }

    animators.add(translateAnimatorY);
  }
}

Related Tutorials