Android: How to make a nice heartbeat animation? [closed]
Asked Answered
C

0

36

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?

Crumple answered 26/5, 2015 at 14:9 Comment(12)
A real beating heart is something creepy you wouldn't want to see...Montano
What's your use case? a medical/sports application? a valentine's day app?Botfly
ok, I know :) it's only a simple effect to catch the eye of the user on a particular imageCrumple
no, it's a game, there is an image I want to manipulate like a beating heart to communicate the message that it's vital to use it.Crumple
I don't need perfection, just wonder if it could be a better way, with more creativityCrumple
Its nice that you are trying to do something different. See this link: https://mcmap.net/q/428407/-how-to-create-imageview-pulse-effect-using-nine-old-androids-animation/3879470 it might be helpful...Swearword
Please.!!! This question shouldn't be closed...Swearword
You could use an animated GIF. Something like this: s386.photobucket.com/user/Snaazzy/media/gif.gif.htmlMontano
it's not possible, gifs aren't supportedCrumple
Who told you that? https://mcmap.net/q/108580/-display-animated-gifMontano
once I tried and didn't work. However my problem is a little more complicated because if I'd want to animate an entire view group I couldn't do this wayCrumple
Check out this link's: github.com/mharkus/Heartbeat-Monitor/blob/master/android/src/… pumpHeart() method and scaleUpListener. They have done a heart beat animation using ViewPropertyAnimator. Also can you show a sample of how your animation is working.Swearword

© 2022 - 2024 — McMap. All rights reserved.