Example usage for android.graphics.drawable ClipDrawable VERTICAL

List of usage examples for android.graphics.drawable ClipDrawable VERTICAL

Introduction

In this page you can find the example usage for android.graphics.drawable ClipDrawable VERTICAL.

Prototype

int VERTICAL

To view the source code for android.graphics.drawable ClipDrawable VERTICAL.

Click Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static void clipDrawable(final View image, Drawable drawable, boolean isActivated) {
    if (drawable == null) {
        return;/* w w  w. ja  va2  s.  com*/
    }
    if (isActivated) {
        final ClipDrawable scaleDrawable = new ClipDrawable(drawable, Gravity.CENTER,
                ClipDrawable.HORIZONTAL | ClipDrawable.VERTICAL);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(scaleDrawable);
        } else {
            image.setBackgroundDrawable(scaleDrawable);
        }
        image.setBackgroundDrawable(scaleDrawable);
        ValueAnimator animator = ValueAnimator.ofInt(0, 10000);
        animator.setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                scaleDrawable.setLevel((Integer) animation.getAnimatedValue());
            }
        });
        animator.start();
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(null);
        } else {
            image.setBackgroundDrawable(null);
        }
    }
}