android-Instagram的心脏动画模仿-FadeScale动画
作者:互联网
我正在尝试创建类似于instagram双击动画的动画,其中,心脏在淡入时从中心放大,然后保持一点点可见,然后在淡出时从中心缩小.
我正在使用此动画:
public void animateHeart(final ImageView view) {
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new AlphaAnimation(0.0f, 1.0f));
animation.addAnimation(new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
animation.setDuration(700);
animation.setRepeatMode(Animation.REVERSE);
view.startAnimation(animation);
}
它对于出现的动画效果很好,但是动画不会反转.
另外,我只希望它动画一次.
有人可以告诉我我在做什么错吗?
提前致谢.
解决方法:
您只用代码开始一个Scale和Alpha动画.
这行:
animation.setRepeatMode(Animation.REVERSE);
显然在AnimationSet中效果不佳,因此您必须将其分别应用于每个Animation.我会推荐这样的东西:
public void animateHeart(final ImageView view) {
ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
prepareAnimation(scaleAnimation);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
prepareAnimation(alphaAnimation);
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(alphaAnimation);
animation.addAnimation(scaleAnimation);
animation.setDuration(700);
animation.setFillAfter(true);
view.startAnimation(animation);
}
private Animation prepareAnimation(Animation animation){
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
return animation;
}
不要忘记
animation.setFillAfter(true);
否则,当动画结束时,您的心会再次出现.
标签:animation,android-imageview,android 来源: https://codeday.me/bug/20191027/1944459.html