Android 动画图像的AnimationDrawable或OnDraw

Android 动画图像的AnimationDrawable或OnDraw,android,Android,我希望屏幕上有20个对象。每个对象都设置了动画,基本上由5帧图像组成。例如,让我们假设一个冒烟的房子。我想知道使用哪种方法(以及为什么) 1-可绘制动画,其中图像在xml文件的动画集中定义。动画设置为无限 2-自定义视图扩展ImageView,其中我在OnDraw方法的某个帧上设置了所需的图像,并在方法结束时继续调用OnDraw(或invalidated) 3-其他一些方法 为了方便起见,我倾向于使用第一种方法,但我不确定正确的方法(或者为什么我不应该使用我的方法) 非常感谢是的,第一个是简单而

我希望屏幕上有20个对象。每个对象都设置了动画,基本上由5帧图像组成。例如,让我们假设一个冒烟的房子。我想知道使用哪种方法(以及为什么)

1-可绘制动画,其中图像在xml文件的动画集中定义。动画设置为无限

2-自定义视图扩展ImageView,其中我在OnDraw方法的某个帧上设置了所需的图像,并在方法结束时继续调用OnDraw(或invalidated)

3-其他一些方法

为了方便起见,我倾向于使用第一种方法,但我不确定正确的方法(或者为什么我不应该使用我的方法)


非常感谢

是的,第一个是简单而好的方法。我以前做过。活动初始化如下所示:

    ImageView imageViewAnimation;
    private AnimationDrawable independentAnimation;

    imageViewAnimation = (ImageView) findViewById(R.id.imageViewAnimation);

        // set the animation drawable as background
        // here demo_logo_animation is an XML

        imageViewAnimation
                .setBackgroundResource(R.drawable.demo_logo_animation);
        // create an animation drawable using the background


        independentAnimation = (AnimationDrawable) imageViewAnimation
                .getBackground();

        // start the animation
        imageViewAnimation.post(new Runnable() {

            @Override
            public void run() {
                // fOR 2.3 DEVICES
                independentAnimation.start();
            }
        });
将所有图像和demo_logo_animation.xml放入res/drawable文件夹中。demo_logo_animation.xml中的属性从上到下依次运行。因此,请小心放置。然后demo_logo_animation.xml看起来像

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

    <item
        android:drawable="@drawable/itv001"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv003"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv006"
        android:duration="@string/log_in_duration"/>


    <item
        android:drawable="@drawable/itv009"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv012"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv015"
        android:duration="@string/log_in_duration"/>


    <item
        android:drawable="@drawable/itv018"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv021"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv024"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv027"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv030"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv033"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv036"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv039"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv042"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv045"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv048"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv051"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv054"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv057"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv060"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv063"
        android:duration="@string/log_in_duration"/>




    <item
        android:drawable="@drawable/itv066"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv069"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv072"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv075"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv078"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv081"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv084"
        android:duration="@string/log_in_duration"/>

    <item
        android:drawable="@drawable/itv087"
        android:duration="@string/log_in_duration"/>


</animation-list>


使用
AnimationDrawable
。不需要重新发明轮子。谢谢。。我假设两个选项的性能是相同的,我没有损失太多