繁体   English   中英

Android动画-逐帧?

[英]Android animation - frame-by-frame?

因此,我是第一次使用android编程,而我要尝试做的第一件事就是创建一个可自行启动的基本动画。 没什么复杂的,只是一个循环的动画。 我试图逐帧坚持,因为它似乎是最基本,最容易理解的。 我看过许多教程/网站/视频(包括android开发站点)有关如何执行此操作的方法,但无法弄清楚我在做什么错。 我确定我在某个地方有一个简单的逻辑错误。 以下是我发布的代码。 有人可以帮我吗? 感谢您的帮助! (此外,根据Nook Developer网站的说法,它专门在NookColor模拟器上运行,该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>
ImageView animImg = (ImageView) findViewById(R.id.animatepic);
animImg.setBackgroundResource(R.drawable.animation);
animSequence = (AnimationDrawable) animImg.getBackground();
animSequence.start();

尝试这个

您是说什么错误吗?

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

这是您可以下载的zip文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM