1.起初 我也只是在anim 文件夹里 写了一个drawable文件 可是没有停歇 只是不停的缩放
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:shareInterpolator="true"
>
<!-- 定义缩放变换 -->
<scale android:fromXScale="0.8"
android:toXScale="1"
android:fromYScale="0.8"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:repeatMode="reverse"
android:duration="500"/>
</set>
2.为了又一个延迟时间 ,九牛二虎之力 一个动画完成 开启另一个动画
final ScaleAnimation animation0 = new ScaleAnimation(0.8f, 1f, 0.8f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation0.setFillAfter(true);
animation0.setDuration(250);
final ScaleAnimation animation1 = new ScaleAnimation(1f,0.8f, 1f, 0.8f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation1.setFillAfter(true);
animation1.setDuration(200);
animation0.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imgHeartbeat.startAnimation(animation1);
}
},0);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animation1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imgHeartbeat.startAnimation(animation0);
}
},1000 );
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
imgHeartbeat.startAnimation(animation0);
废弃的代码 有待研究
ObjectAnimator animator1 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1f, 1.2f, 1);
animator1.setDuration(500);
// animator1.setRepeatCount(-1);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleY", 1f, 1.2f, 1);
animator2.setDuration(500);
// animator2.setRepeatCount(-1);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1, 0.1f, 1);
animator3.setDuration(2000);
// animator3.setRepeatCount(-1);
ObjectAnimator animator4 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleY", 1, 0.1f, 1);
animator4.setDuration(2000);
// animator4.setRepeatCount(-1);
ObjectAnimator animator5 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1f, 1f, 1);
animator5.setDuration(3000);
// animator5.setRepeatCount(-1);;
// Scal
AnimatorSet set=new AnimatorSet();
set.play(animator1).with(animator2);
set.play(animator3).with(animator4);
set.play(animator3).after(animator1);
set.play(animator5).after(animator3);
set.setDuration(3000);
set.setInterpolator(new LinearInterpolator());
// set.start();