Android 动画 - 逐帧?

发布于 2024-12-07 18:18:43 字数 2344 浏览 0 评论 0原文

所以,我是 android 编程的新手,我想做的第一件事就是创建一个自行启动的基本动画。没什么复杂的,只是一个循环动画。我试图坚持逐帧,因为它似乎是最基本、最容易理解的。我已经查看了许多关于如何执行此操作的教程/网站/视频(包括 Android 开发网站),但无法弄清楚我做错了什么。我确信我在某个地方有一个简单的逻辑错误。下面是我发布的代码。有人可以帮我吗?谢谢您的帮助! (另外,作为旁注,这是专门在 NookColor 模拟器上运行的,根据 Nook 开发者网站,nook 运行最新的 Android。不幸的是,Nook 网站没有提供教程或任何有用的内容,只有与 Android 开发者相同的链接。)

//main class

public class WallpaperActivity extends Activity {

    AnimationDrawable animSequence;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView animImg = (ImageView) findViewById(R.id.animatepic);
        animImg.setBackgroundResource(R.drawable.animation);
        animSequence = (AnimationDrawable) animImg.getBackground();

    }


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


//animation.xml  class ( << this is not my main.xml class)

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/animatepic" android:oneshot="false" >

    <item android:drawable="@drawable/a" android:duration="200" />
    <item android:drawable="@drawable/b" android:duration="200" />
    <item android:drawable="@drawable/c" android:duration="200" />
    <item android:drawable="@drawable/d" android:duration="200" />
    <item android:drawable="@drawable/e" android:duration="200" />
    <item android:drawable="@drawable/f" android:duration="200" />
    <item android:drawable="@drawable/g" android:duration="200" />
    <item android:drawable="@drawable/h" android:duration="200" />
    <item android:drawable="@drawable/i" android:duration="200" />
    <item android:drawable="@drawable/j" android:duration="200" />
    <item android:drawable="@drawable/k" android:duration="200" />
    <item android:drawable="@drawable/l" android:duration="200" />
    <item android:drawable="@drawable/m" android:duration="200" />
    <item android:drawable="@drawable/n" android:duration="200" />
    <item android:drawable="@drawable/o" android:duration="200" />
    </animation-list>

So, I'm new to programming with android and one of the first thing I'm trying to do is create a basic animation that starts on its own. Nothing complicated, just a looping animation. I am trying to stick with frame-by-frame because it seems the most basic and easiest to understand. I have looked at many tutorials/websites/videos (including the android dev sites) on how to do this and can't figure out what I'm doing wrong. I'm sure I have a simple logic error somewhere. Below is my posted code. Can someone help me out? Thank you for the help! (Also, as a side note this is specifically running on a NookColor emulator, according to Nook Developer site, the nook runs the latest android. Unfortunately the Nook site gives no tutorials or anything useful, only the same links to Android developers.)

//main class

public class WallpaperActivity extends Activity {

    AnimationDrawable animSequence;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView animImg = (ImageView) findViewById(R.id.animatepic);
        animImg.setBackgroundResource(R.drawable.animation);
        animSequence = (AnimationDrawable) animImg.getBackground();

    }


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


//animation.xml  class ( << this is not my main.xml class)

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/animatepic" android:oneshot="false" >

    <item android:drawable="@drawable/a" android:duration="200" />
    <item android:drawable="@drawable/b" android:duration="200" />
    <item android:drawable="@drawable/c" android:duration="200" />
    <item android:drawable="@drawable/d" android:duration="200" />
    <item android:drawable="@drawable/e" android:duration="200" />
    <item android:drawable="@drawable/f" android:duration="200" />
    <item android:drawable="@drawable/g" android:duration="200" />
    <item android:drawable="@drawable/h" android:duration="200" />
    <item android:drawable="@drawable/i" android:duration="200" />
    <item android:drawable="@drawable/j" android:duration="200" />
    <item android:drawable="@drawable/k" android:duration="200" />
    <item android:drawable="@drawable/l" android:duration="200" />
    <item android:drawable="@drawable/m" android:duration="200" />
    <item android:drawable="@drawable/n" android:duration="200" />
    <item android:drawable="@drawable/o" android:duration="200" />
    </animation-list>

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

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

发布评论

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

评论(2

岁月苍老的讽刺 2024-12-14 18:18:43

你有说你遇到了什么错误吗?

无论如何,您的代码示例似乎已更新

您可以下载以下zip 文件

Did you say what error you were getting?

In any case, your code example seems to have been updated.

Here is its zip file you can download.

惯饮孤独 2024-12-14 18:18:43
ImageView animImg = (ImageView) findViewById(R.id.animatepic);
animImg.setBackgroundResource(R.drawable.animation);
animSequence = (AnimationDrawable) animImg.getBackground();
animSequence.start();

试试这个

ImageView animImg = (ImageView) findViewById(R.id.animatepic);
animImg.setBackgroundResource(R.drawable.animation);
animSequence = (AnimationDrawable) animImg.getBackground();
animSequence.start();

try this

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