我已经苦苦挣扎了几天,最后决定来求助。这个问题应该非常简单,我一定是错过了一些非常基础的东西。
我有一个包含图像定义的XML布局页面。我有两个anim XML页面,一个用于将alpha从0更改为1,另一个用于将alpha从1更改为0,以创建"闪烁"效果。因此,alphaAnimation在XML中定义,我只需要调用它即可。
图像出现了,但没有循环闪烁效果。
public class blinker extends Activity {
//create name of animation
Animation myFadeInAnimation;
Animation myFadeOutAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scanning_view);
//grab the imageview and load the animations
ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_in);
Animation myFadeOutAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_out);
//fade it in, and fade it out.
myImageView.startAnimation(myFadeInAnimation);
myImageView.startAnimation(myFadeOutAnimation);
}
}
在Anim资源中有两个XML动画布局:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="50" android:repeatCount="infinite"/>
</set>
而另一个是:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000" android:repeatCount="infinite"/>
</set>