get Drop Elevation Value ValueAnimator - Android android.animation

Android examples for android.animation:ValueAnimator

Description

get Drop Elevation Value ValueAnimator

Demo Code


//package com.java2s;
import android.animation.ValueAnimator;

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 getDropElevationValue(
            final View targetView, int duration) {
        return getDropElevationValue(targetView, duration,
                DEFUALT_MIN_ELEVATION, DEFUALT_DEC_ELEVATION);
    }/*from w  ww . j  av  a 2  s.co  m*/

    public static ValueAnimator getDropElevationValue(
            final View targetView, int duration, final int mimElevation,
            final int decElevation) {
        ValueAnimator decElevationValueAnim = ValueAnimator.ofInt(1);
        decElevationValueAnim
                .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float fraction = animation.getAnimatedFraction();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            targetView.setElevation(fraction * decElevation
                                    + mimElevation);
                        }
                    }
                });
        decElevationValueAnim.setDuration(duration);
        return decElevationValueAnim;
    }
}

Related Tutorials