如何在Android上进行逐帧动画?

如何在Android上进行逐帧动画?,android,animation,mobile,png,Android,Animation,Mobile,Png,我试图找出如何在一个良好的帧速率png帧动画 我有一堆png(大概1500个png姿势),我需要一个接一个地播放它们(就像一个会说话的应用程序,以tom cat为例) 我已经尝试过SurfaceView、normal View、AnimationDrawable和ImageView(用一个线程设置睡眠背景(33)[30帧/秒]),但这些方法都不能与CPU性能差的手机(如HTC Desire a)上的tom cat相比获得好的帧速率 还可以说,我已经添加了一些选项来设置图像的in-SampleSi

我试图找出如何在一个良好的帧速率png帧动画

我有一堆png(大概1500个png姿势),我需要一个接一个地播放它们(就像一个会说话的应用程序,以tom cat为例)

我已经尝试过SurfaceView、normal View、AnimationDrawable和ImageView(用一个线程设置睡眠背景(33)[30帧/秒]),但这些方法都不能与CPU性能差的手机(如HTC Desire a)上的tom cat相比获得好的帧速率

还可以说,我已经添加了一些选项来设置图像的in-SampleSize,以防它需要更多内存或处理速度

我认为独特的方法是加载大量PNG,在SurfaceView上绘制,在播放的同时加载更多PNG并回收其他位图

有人能帮我吗?至少有一些代码


谢谢

给你。。。试试这个……:) 在ur values文件夹中创建这样的XML文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="frames">
    <item>@drawable/pak1_1</item>
    <item>@drawable/pak1_2</item>
    <item>@drawable/pak1_3</item>
    <item>@drawable/pak1_4</item>
    <item>@drawable/pak1_5</item>
</array>
</resources>

@可抽出式/pak1_1
@可抽出式/pak1_2
@可抽出式/pak1_3
@可抽出式/pak1_4
@可抽出式/pak1_5
现在请尝试以下代码:

public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
           Resources res = getResources();
           TypedArray FrameImages = res.obtainTypedArray(R.array.frames);
           animation = new AnimationDrawable();
           for (int i = 0; i < 1500; i++) {
               Drawable drawable = FrameImages.getDrawable(i);
               animation.addFrame(drawable, 33);
           }
           animation.setOneShot(false);
           ImageView imageAnim =  (ImageView) findViewById(R.id.img);
           imageAnim.setBackgroundDrawable(animation);
           // run the start() method later on the UI thread
           imageAnim.post(new Starter());
       }

       class Starter implements Runnable {
           public void run() {
               animation.start();        
           }
       }
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res=getResources();
TypedArray FrameImages=res.obtainTypedArray(R.array.frames);
animation=新的AnimationDrawable();
对于(int i=0;i<1500;i++){
Drawable Drawable=FrameImages.getDrawable(i);
动画。添加帧(可绘制,33);
}
动画.setOneShot(假);
ImageView imageAnim=(ImageView)findViewById(R.id.img);
imageAnim.setBackgroundDrawable(动画);
//稍后在UI线程上运行start()方法
imageAnim.post(新的Starter());
}
类Starter实现可运行的{
公开募捐{
animation.start();
}
}

嗯,我已经使用了AnimationDrawable…在ImageView下面添加一个背景图像时速度很慢,而且由于PNG太多,内存也会溢出…而且,此策略在30帧后崩溃。i、 e。动画列表中的30项