android – Repeat pulse Animation-ThrowExceptions

Exception or error:

I’m trying to create a Infinite pulsing effect in a ImageView.
But how is it possible to keep the offset?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5"/>
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="700"
    android:toXScale="2"
    android:toYScale="2"/>
</set>
How to solve:

This will make your (Image)View pulsate up to 1.2 its size and back, repeatedly.

ImageView iv = (ImageView) findViewById(R.id.my_imageview);

ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(
                    iv,
                    PropertyValuesHolder.ofFloat("scaleX", 1.2f),
                    PropertyValuesHolder.ofFloat("scaleY", 1.2f));
scaleDown.setDuration(310);

scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
scaleDown.setRepeatMode(ObjectAnimator.REVERSE);

scaleDown.start();

###

You can set startOffset values for each animations in your set.

###

If you want to create infinite animation, the best way would be to create custom View and in onDraw create your animation. For example: How to animate a path on canvas – android

Actually you can do animation with SurfaceView too.

Leave a Reply

Your email address will not be published. Required fields are marked *