我在我的资源/可绘制文件夹中有很多图像作为帧(比如大约200).使用这个图像我想运行动画.最长的动画是80Frames.我成功地能够通过单击某些按钮来运行动画,但对于某些动画,它给了我OutOfMemoryError,说VM无法提供这样的内存.它超出了VM预算.我计算所有图像的大小约10MB.每个图像的大小为320x480像素.
我尝试谷歌搜索,发现我需要使用System.gc()方法显式调用垃圾收集器.我已经做到了,但我仍然得到一些时间错误的记忆.任何人都可以请帮助我.
一些代码: -
ImageView img = (ImageView)findViewById(R.id.xxx);
img.setBackgroundResource(R.anim.angry_tail_animation);
AnimationDrawable mailAnimation = (AnimationDrawable) img.getBackground();
MediaPlayer player = MediaPlayer.create(this.getApplicationContext(), R.raw.angry);
if(mailAnimation.isRunning()) {
mailAnimation.stop();
mailAnimation.start();
if (player.isPlaying()) {
player.stop();
player.start();
}
else {
player.start();
}
}
else {
mailAnimation.start();
if (player.isPlaying()) {
player.stop();
player.start();
}
else {
player.start();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在点击按钮时编写的代码.....
res/drawable/anim中的资源文件
<?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/cat_angry0000" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0001" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0002" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0003" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0004" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0005" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0006" android:duration="50"/>
<item android:drawable="@drawable/cat_angry0007" …Run Code Online (Sandbox Code Playgroud)