Collapse a view out by scaling it from its current scaled value to 0. - Android Animation

Android examples for Animation:Scale Animation

Description

Collapse a view out by scaling it from its current scaled value to 0.

Demo Code


import java.util.List;

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

public class Main {
  private static Interpolator sDecelerateQuintInterpolator;
  /**/*w  w  w  . j a v a2s. 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 = 100;

  /**
   * Collapse a view out by scaling it from its current scaled value to 0.
   */
  public static void addCollapseOutAnimators(List<Animator> animators, final View view, int animationDelay) {
    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    final ObjectAnimator scaleAnimatorY = ObjectAnimator.ofFloat(view, View.SCALE_Y, view.getScaleY(), 0);
    scaleAnimatorY.setInterpolator(sDecelerateQuintInterpolator);
    scaleAnimatorY.setDuration(sAnimationDuration);
    scaleAnimatorY.setStartDelay(animationDelay);
    scaleAnimatorY.addListener(new AnimatorListenerAdapter() {
      @Override
      public void onAnimationEnd(Animator animation) {
        view.setScaleY(0);
        view.setLayerType(View.LAYER_TYPE_NONE, null);
      }
    });

    animators.add(scaleAnimatorY);
  }

  /**
   * Collapse a view out by scaling it from its current scaled value to 0. The
   * animators are expected to run immediately without a start delay.
   */
  public static void addCollapseOutAnimators(List<Animator> animators, final View view) {
    addCollapseOutAnimators(animators, view, 0 /* animation delay */);
  }
}

Related Tutorials