Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.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/7/jsf/5.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
Android SD卡中的位图动画和不带XML的位图动画?_Android_Xml_Bitmap_Android Animation_Android Drawable - Fatal编程技术网

Android SD卡中的位图动画和不带XML的位图动画?

Android SD卡中的位图动画和不带XML的位图动画?,android,xml,bitmap,android-animation,android-drawable,Android,Xml,Bitmap,Android Animation,Android Drawable,假设您的程序在运行时生成N个位图,并将它们存储在仿真程序的SD卡中,您希望创建一种视频,然后快速连续地替换它们 imageView.setImageBitmap(bitmap)中的for不起作用,因为它只显示最后一个位图,所以我应该使用动画,对吗 教程说我应该创建如下XML: <animation-list android:id="@+id/selected" android:oneshot="false"> <item android:drawable="@drawa

假设您的程序在运行时生成N个位图,并将它们存储在仿真程序的SD卡中,您希望创建一种视频,然后快速连续地替换它们

imageView.setImageBitmap(bitmap)
中的
for
不起作用,因为它只显示最后一个位图,所以我应该使用动画,对吗

教程说我应该创建如下XML:

 <animation-list android:id="@+id/selected" android:oneshot="false">
   <item android:drawable="@drawable/wheel0" android:duration="50" />
   <item android:drawable="@drawable/wheel1" android:duration="50" />
   <item android:drawable="@drawable/wheel2" android:duration="50" />
   <item android:drawable="@drawable/wheel3" android:duration="50" />
   <item android:drawable="@drawable/wheel4" android:duration="50" />
   <item android:drawable="@drawable/wheel5" android:duration="50" />
 </animation-list>
在我的replayAsync任务中,在doInBackground方法中,我有以下内容:

        runOnUiThread(new Runnable(){

            @Override
            public void run() {
                for ( int c = 0; c < 10; c++){

                    String path = temp + File.separator + c + ".jpg";   //c is the filename!

                    Bitmap myBitmap = BitmapFactory.decodeFile(path);
                    frameAnimation.addFrame(Drawable.createFromPath(path), 200);

                }
                frameAnimation.start();                 
            }

        });
但若在编译时并没有任何要插入的项,那个么我就无法创建它,所以动画xml中的动画列表将为空

我能做什么


谢谢大家!

程序崩溃时,您是否查看了日志猫?它可能会抱怨replayView为null,因为您试图在初始化它之前获取背景,然后再向下3行

另外,当你做了for循环时,是否有延迟

最后,动画可绘制可能不是最好的选择。根据图像大小和图像数量,您可能会遇到内存不足错误。这也不是最快的方法。我建议使用画布或更好的纹理视图,甚至可以查看opengl解决方案

        runOnUiThread(new Runnable(){

            @Override
            public void run() {
                for ( int c = 0; c < 10; c++){

                    String path = temp + File.separator + c + ".jpg";   //c is the filename!

                    Bitmap myBitmap = BitmapFactory.decodeFile(path);
                    frameAnimation.addFrame(Drawable.createFromPath(path), 200);

                }
                frameAnimation.start();                 
            }

        });
replayView.setBackgroundResource(R.drawable.animation);