Android AnimationDrawable 启动,完成后挂在第一帧

发布于 2024-11-25 15:37:11 字数 1272 浏览 7 评论 0原文

我试图让我的 Android 应用程序上的 AnimationDrawable 重复。 我将 android:oneshot 配置为 false。 (尝试使用java和XML) 尽管如此,每当播放动画时,一旦完成,它就会返回到第一帧,并停止

这是我的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/network_scanning" android:oneshot="false">  
<item android:drawable="@drawable/network_wireless_0" android:duration="300" />
<item android:drawable="@drawable/network_wireless_1" android:duration="300" />
<item android:drawable="@drawable/network_wireless_2" android:duration="300" />
<item android:drawable="@drawable/network_wireless_3" android:duration="300" />
<item android:drawable="@drawable/network_wireless_4" android:duration="300" />
</animation-list>

这是启动动画的代码:

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

    LinearLayout network = (LinearLayout) findViewById(R.id.wifi_anim);
    AnimationDrawable anim = (AnimationDrawable) network.getBackground();
    if (hasFocus)
    {
        anim.setOneShot(false);
        anim.setCallback(network);
        anim.setVisible(true, true);
        anim.start();
    }

}

I'm trying to get the AnimationDrawable on my Android app to repeat.
I configured the android:oneshot on false. (tried both with java and with XML)
Still, whenever the animation is played, once it's done, it goes back to the first frame, and stops

This is my XML file

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/network_scanning" android:oneshot="false">  
<item android:drawable="@drawable/network_wireless_0" android:duration="300" />
<item android:drawable="@drawable/network_wireless_1" android:duration="300" />
<item android:drawable="@drawable/network_wireless_2" android:duration="300" />
<item android:drawable="@drawable/network_wireless_3" android:duration="300" />
<item android:drawable="@drawable/network_wireless_4" android:duration="300" />
</animation-list>

and this is the code to start the animation:

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

    LinearLayout network = (LinearLayout) findViewById(R.id.wifi_anim);
    AnimationDrawable anim = (AnimationDrawable) network.getBackground();
    if (hasFocus)
    {
        anim.setOneShot(false);
        anim.setCallback(network);
        anim.setVisible(true, true);
        anim.start();
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文