Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 循环动画可绘制_Java_Android_Xml_Android Drawable_Animationdrawable - Fatal编程技术网

Java 循环动画可绘制

Java 循环动画可绘制,java,android,xml,android-drawable,animationdrawable,Java,Android,Xml,Android Drawable,Animationdrawable,我正在尝试动画一些png,我会循环动画。这是我的代码: wave.setBackgroundResource(R.drawable.wave_animation); frameAnimation = (AnimationDrawable)wave.getBackground(); frameAnimation.setCallback(wave); frameAnimation.setVisible(t

我正在尝试动画一些png,我会循环动画。这是我的代码:

wave.setBackgroundResource(R.drawable.wave_animation);
                frameAnimation = (AnimationDrawable)wave.getBackground();
                frameAnimation.setCallback(wave);
                frameAnimation.setVisible(true, true);
                frameAnimation.start();
这里是带有png的xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="true">
    <item android:drawable="@drawable/wave_01" android:duration="200" />
    <item android:drawable="@drawable/wave_02" android:duration="200" />
    <item android:drawable="@drawable/wave_03" android:duration="200" />
    <item android:drawable="@drawable/wave_04" android:duration="200" />
</animation-list>


我还添加了android:oneshot=false,但不起作用。

这是在图像上运行动画。在开始动画之前,需要确保动画尚未运行。在启动动画之前添加一个检查,如果动画正在运行,则停止动画,然后启动动画

private void startAnimation(){

        imageView.setImageResource(R.drawable.img_animation);

        AnimationDrawable imgAnimation = (AnimationDrawable) imageView.getDrawable();

        if (imgAnimation .isRunning()) {
            imgAnimation .stop();
        }
        imgAnimation .start();

    }
img_animation.xml//检查下面的注释

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" >

    <!-- 24 frame per sec | 1000ms/24 i.e. 41ms per image -->
    <item
        android:drawable="@drawable/ball01" android:duration="41"/>
    <item
        android:drawable="@drawable/ball02" android:duration="41"/>
   ..........so on ..........
    <item
        android:drawable="@drawable/ball24" android:duration="41"/>

     <!-- Reset to first when animation stops-->
    <item
        android:drawable="@drawable/ball01"
        android:duration="10"/>

</animation-list>

以此类推。。。。。。。。。。

上面的代码显示

    android:oneshot="true"
这将使动画运行一次且仅运行一次

你说你试过android:oneshot=“false”。
这对于多次运行动画列表至关重要。所以把它放回去

请记住,运行动画是一个“后台”任务,无论其自身设置如何,当主/前台任务完成时,该任务将终止


如果你想要别的东西,你可能需要采取不同的方法

只需将android:oneshot=“false”更改为这样

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="false">
    <item android:drawable="@drawable/wave_01" android:duration="200" />
    <item android:drawable="@drawable/wave_02" android:duration="200" />
    <item android:drawable="@drawable/wave_03" android:duration="200" />
    <item android:drawable="@drawable/wave_04" android:duration="200" />
</animation-list>

我更新了答案,如果有帮助,请告诉我。