1
我试图做的是将ImageView从正常大小缩放到20%,然后返回。这应该是循环的。我已经用下面的代码完成了这个工作,但是它并不正确。更多下面。缩放动画按预期工作不正常
动画/ scale.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.2"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />
<scale
android:startOffset="1000"
android:duration="1000"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />
</set>
然后在我的代码,我做
private void scaleAnimation() {
final Animation scaler = AnimationUtils.loadAnimation(this, R.anim.scale);
scaler.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
animation.reset();
animation.startNow();
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
scale.startAnimation(scaler);
}
}, 2000);
}
我有处理程序存在,所以我可以看到在开始发生。
问题是一种很难解释的问题..我的图像在动画开始后似乎会缩小然后执行动画。因此,图像应该显示2秒钟。正如动画开始,它突然变得更大,看起来是25% - 50%,然后动画正确执行。一旦动画结束,图像会很快调整到原始大小,然后再放大,然后动画重新开始。
我已经尝试了几个不同的图像没有区别。这是我的理解,从XScale = 1.0开始没有缩放的动画,即图像。希望有人能够阐明我做错了什么或者我误解了这些概念。
干杯
此外,您不必担心添加自己的AnimationListeners重新开始动画 – cheezy
这很棒。完美工作,代码少。非常好的建议,谢谢! –