Expand a view into view by scaling up vertically from 0. - Android User Interface

Android examples for User Interface:View

Description

Expand a view into view by scaling up vertically from 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;
  /**//from  ww w .j  ava2s  .  co  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;

  /**
   * Expand a view into view by scaling up vertically from 0.
   */
  public static void addExpandInAnimators(List<Animator> animators, final View view, int animationDelay) {
    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    view.setScaleY(0);

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

    animators.add(scaleAnimatorY);
  }
}

Related Tutorials