Android: How to make a nice heartbeat animation?

user3290180 picture user3290180 · May 26, 2015 · Viewed 13.2k times · Source

This is my solution

anim/pulse.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:duration="300"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toXScale="0.75"
    android:toYScale="0.75"
    android:interpolator="@android:interpolator/bounce" />
<scale
    android:duration="100"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toXScale="1.25"
    android:toYScale="1.25"
    android:interpolator="@android:interpolator/bounce" />
 </set>

then in activity.java:

ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.pulse));

I'm not satisfied because a real beating heart has more elegant contractions. How could it be improved?

EDIT: I think that a fine effect would be something that imitate the heart beat. A fast contraction followed by another one. Maybe the last could be fast in the first half and then reverse slowly for the second half. Is there a way to make all these effects triggering each other?

Answer