我正在使用 Robolectric3.2.1 做一些UT。在 TestActivity 的 onCreate()期间,我启动了 anmation ,如下所示:
protected void onCreate(Bundle savedInstanceState){
...
mImageView.startAnimation(createAnim());
...
}
创建animationSet的方法:
private AnimationSet createAnim(){
AnimationSet scaleAndAlphaAnim = (AnimationSet)AnimationUtils.loadAnimation(this, R.anim.radar_scale_alpha_anim);
scaleAndAlphaAnim.setInterpolator(new LinearInterpolator());
for (Animation anim : scaleAndAlphaAnim.getAnimations()) {
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(1500L);
}
return scaleAndAlphaAnim;
}
和动画文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.75"
android:fromYScale="0.75"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.5"
android:toYScale="1.5"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
运行代码后:
Robolectric.setupActivity(TestActivity.class);
主线程在 mImageView.startAnimation(createAnim())中陷入无限循环。但代码在我的真实设备上运行良好。现在我很困惑。谁能告诉我为什么?