我需要用四张图片开始眨眼。我使用for循环为每个对象启动动画。当你开始眨眼时,动画就不是正弦的了。
我想要达到的效果是让图像同时闪烁。我该怎么做呢?
代码:数组内部有四个图像资源
for(AnimationDrawable image : array){
AnimationDrawable animationDrawable = (AnimationDrawable) image.getBackground();
animationDrawable.start();
}发布于 2014-12-05 06:55:34
你不需要为此使用循环。创建补间动画资源文件(将其扩展为AnimationDrawable)后,将其设置为ImageView的android:src,然后在代码中,像这样简单地调用:
AnimationDrawable animationDrawable = (AnimationDrawable) image.getBackground();
在活动中,覆盖public void onWindowFocusChange()并启动动画,如下所示:
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
animationDrawable.start();
}您需要覆盖该方法的原因是,您只想在窗口获得焦点或与用户交互后立即启动动画。希望这能有所帮助。
如下所示创建补间动画资源,通过其文件名进行引用,并且必须将其放在drawable文件夹中
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/yourDrawable1" android:duration="200" />
<item android:drawable="@drawable/yourDrawable2" android:duration="200" />
<item android:drawable="@drawable/yourDrawable3" android:duration="200" />
</animation-list>发布于 2014-12-05 06:59:43
这是我的工作:
int []mImageArray = {R.drawable.img1, R.drawable.img2, R.drawable.img3};
final Handler mHandler = new Handler();
Runnable runnable = new Runnable()
{
int i = 0;
public void run()
{
mImageView.setImageResource(mImageArray[i]);
i++;
if (i > mImageArray.length - 1)
{
i = 0;
}
mHandler.postDelayed(this, 500); // Set the interval delay
}
};
mHandler.postDelayed(runnable, 4000); // Set the initial delay
} https://stackoverflow.com/questions/27305552
复制相似问题