【发布时间】:2012-11-22 15:35:01
【问题描述】:
我在我的应用程序的许多活动中使用动画绘图。这是初始化它们的代码:
public void prepareVideo (int resourceBall, String animation, int width, int height ){
imgBall = (ImageView)findViewById(resourceBall);
imgBall.setVisibility(ImageView.VISIBLE);
String resourceNameAnimation = animation;
int id_res = getResources().getIdentifier(resourceNameAnimation, "drawable", getPackageName());
imgBall.setBackgroundResource(id_res);
LayoutParams latoutFrame = imgBall.getLayoutParams();
latoutFrame.width = width;
latoutFrame.height = height;
imgBall.setLayoutParams(latoutFrame);
frame = (AnimationDrawable) imgBall.getBackground();
}
然后我打电话给: imgBall.post(new StartAnimation());
调用runnable:
class StartAnimation implements Runnable {
public void run() {
frame.start();
}
}
问题是我使用了许多使用相同 xml(逐帧)的动画。我必须在许多具有相同动画的活动中调用此方法。最后我得到一个内存不足的错误。我正在尝试释放屏幕之间的内存:
for (int i = 0; i < frame.getNumberOfFrames(); ++i){
Drawable frame_rescue = frame.getFrame(i);
if (frame_rescue instanceof BitmapDrawable) {
((BitmapDrawable)frame_rescue).getBitmap().recycle();
}
frame_rescue.setCallback(null);
问题是,当我再次尝试使用资源时,会出现其他错误: "尝试使用回收位图"
有人知道其他释放内存的方法吗?
【问题讨论】: