我具有跟随动画,该动画将图像从“不可见”缩放到60dp x 60dp,从而增加了反弹效果。完成此操作后,它将消失,并具有另一个缩放效果。
bounce_animation.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <set android:interpolator="@android:anim/bounce_interpolator"> <scale android:fromXScale="0.1" android:fromYScale="0.1" android:toXScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="1600" /> </set> <set> <scale android:startOffset="1900" android:duration="200" android:pivotX="50%" android:pivotY="50%" android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="0" android:toYScale="0" /> </set> </set>
这是我要使用的代码
MainActivity.java
final ImageView likeBig = findViewById(R.id.like_big); final Animation bounceAnimation = AnimationUtils.loadAnimation(this, R.anim.bounce_animation); bounceAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { likeBig.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { likeBig.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animation animation) { } });
问题是,当我执行
likeBig.setVisibility(View.VISIBLE);
时,在比例动画开始播放之前,图像会在几分之一秒的时间内变为可见。在动画开始之前,我需要图像不可见。
我的方法有什么问题?
我具有跟随动画,该动画将图像从“不可见”缩放到60dp x 60dp,从而增加了反弹效果。完成此操作后,它会消失,并带有另一个缩放效果bounce_animation.xml
[我只能猜测为什么View
在动画开始时全尺寸可见:也许onAnimationStart()
在动画开始计算下一个更改时但在首次更新屏幕之前触发?