我正在尝试在Android中执行逐帧动画。为此,我创建了一个名为“ anim.xml”的xml文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/square0" android:duration="100" />
<item android:drawable="@drawable/square1" android:duration="100" />
<item android:drawable="@drawable/square2" android:duration="100" />
<item android:drawable="@drawable/square3" android:duration="100" />
<item android:drawable="@drawable/square4" android:duration="100" />
<item android:drawable="@drawable/square5" android:duration="100" />
</animation-list>
然后在我定义的框架布局中,我尝试将其设置为背景,并像这样在onCreate上启动它:
FrameLayout imgView = (FrameLayout)findViewById(R.id.frameLayout1);
imgView.setBackgroundResource(R.drawable.anim);
AnimationDrawable anim = (AnimationDrawable) imgView.getBackground();
anim.start();
我正在经历的只是第一帧,但是我要寻找的是正方形动画循环播放。您对我做错了什么吗?
干杯。
最佳答案
在尝试使动画以onCreate方法开始时,我遇到过一些问题。尝试用以下内容重新填充最后一行:
imgView.post(new Runnable()
{
@Override
public void run()
{
anim.start();
}
});
这将使您在执行onCreate之后动画开始。
关于android - 关于逐帧动画的特定于问题的Android问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7149346/