【发布时间】:2011-04-23 19:59:32
【问题描述】:
我为此苦苦挣扎了几天,终于决定问一下。它是如此简单,我必须错过一些非常基本的东西。
我有一个定义了图像的 XML 布局页面。我有两个动画 XML 页面,一个用于将 alpha 从 0 更改为 1,另一个从 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>
【问题讨论】:
-
嗨查理,爱你的表演者。 :) 我编辑了原始帖子,添加了两个 XML 文件(fade_in.xml 和 fade_out.xml)