gpt4 book ai didi

android - 关于逐帧动画的问题特定的android问题

转载 作者:行者123 更新时间:2023-11-29 15:30:43 25 4
gpt4 key购买 nike

我正在尝试在 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();

我遇到的只是第一帧,但我想要的是循环播放的方 block 动画。你对我做错了什么有什么意见吗?

干杯。

最佳答案

在我看来,对于这种情况,Matt 的解决方案似乎有点过于强大。您可以简单地移动您对 start() 的调用onWindowFocusChanged() 的方法方法,因为此时 AnimationDrawable完全贴在窗口上,实际上可以启动。像这样:

@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
anim.start();
}

在你的 onCreate() 中做所有其他的事情方法并制作AnimationDrawable一个类变量,因此您可以从 onWindowFocusChanged() 访问它方法。

关于android - 关于逐帧动画的问题特定的android问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com