【发布时间】:2011-03-09 06:36:43
【问题描述】:
我有不同的图像,比如 100 张左右。现在,我想对它们应用动画。我希望我的 ImageView 在指定的时间间隔后获取每个图像,但是当图像发生变化时,每个图像都应该 FadeIn 或 FadeOut。我将我的图像放在@drawable/[list_of_images].xml 文件中:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/a1" android:duration="1000"/>
<item android:drawable="@drawable/a2" android:duration="2000"/>
<item android:drawable="@drawable/a3" android:duration="3000"/>
<item android:drawable="@drawable/a4" android:duration="500"/>
然后我可以使用以下方法根据它们在 ImageView 中的时间间隔成功更改这些图像:
public class AnimTest extends Activity
{
AnimationDrawable myAnim;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.anim);
ImageView myIV = (ImageView) findViewById(R.id.image_view);
myIV.setBackgroundResource(R.drawable.list_of_images.xml);
myAnim = (AnimationDrawable) myIV.getBackground();
}
public boolean onTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
myAnim.start();
return true;
}
return super.onTouchEvent(event);
}
}
问题是我无法弄清楚如何在每张图像上应用淡入淡出效果,而它们正在被上述动画改变。我可以在整个图像列表上应用淡入淡出动画,但不能在每张图像上都这样做。我是否朝着正确的方向实现此功能?如果没有,请引导我走向正确的道路。
问候, 哈瓦尔
【问题讨论】:
标签: android