get Rise Elevation Value - Android android.view.animation

Android examples for android.view.animation:Translate Animation

Description

get Rise Elevation Value

Demo Code

import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;

public class Main {

  private static final int DEFUALT_MIN_ELEVATION = 1;
  private static final int DEFUALT_DEC_ELEVATION = 20;

  public static ValueAnimator getRiseElevationValue(final View targetView, int duration, final int mimElevation,
      final int maxElevation) {
    ValueAnimator addElevationValueAnim = ValueAnimator.ofInt(1);
    addElevationValueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
      @Override/*from  w  w  w .j  a va 2 s.c o  m*/
      public void onAnimationUpdate(ValueAnimator animation) {
        float fraction = animation.getAnimatedFraction();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
          targetView.setElevation((1 - fraction) * maxElevation + mimElevation);
        }
      }
    });
    addElevationValueAnim.setDuration(duration);
    return addElevationValueAnim;
  }

  public static ValueAnimator getRiseElevationValue(final View targetView, int duration) {
    return getRiseElevationValue(targetView, duration, DEFUALT_MIN_ELEVATION, DEFUALT_DEC_ELEVATION);
  }


}

Related Tutorials