animate Heart Beat - Android android.view.animation

Android examples for android.view.animation:Effect Animation

Description

animate Heart Beat

Demo Code

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.Interpolator;

public class Main {

  public static Interpolator ANTICIPATE = new AnticipateInterpolator(2.8f);

  public static void animateHeartBeat(View view) {
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.1f);
    scaleX.setInterpolator(ANTICIPATE);//ww  w.  j  a  va 2s . c o  m
    scaleX.setRepeatCount(1);
    scaleX.setRepeatMode(ValueAnimator.REVERSE);
    scaleX.setDuration((long) (200));
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.1f);
    scaleY.setInterpolator(ANTICIPATE);
    scaleY.setRepeatCount(1);
    scaleY.setRepeatMode(ValueAnimator.REVERSE);
    scaleY.setDuration((long) (200));

    AnimatorSet set1 = new AnimatorSet();
    set1.playTogether(scaleX, scaleY);

    AnimatorSet set2 = new AnimatorSet();
    set2.playTogether(scaleX, scaleY);

    AnimatorSet animSet = new AnimatorSet();
    animSet.playSequentially(set1, set2);
    animSet.start();
  }

}

Related Tutorials