我已经准备好节数可绘制animations.when应用推出的第一个动画将start.i有两个按钮(下一个和以前)有相同的activity.when我点击下一步按钮我得到异常喜欢,如何解决android中的OutOfMemoryError?
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
我的代码,
为了得到从绘制绘制动画,
private void getAnimationForLetters(int mAnim) {
// TODO Auto-generated method stub
String anim = "capital_anim_" + new Integer(mAnim).toString();
final int resID = getApplicationContext().getResources().getIdentifier(
anim, "drawable", "my-package-name");
mImgLetter.clearAnimation();
mImgLetter.setBackgroundResource(resID);
mImgLetter.post(new Runnable() {
public void run() {
loadingAnimation = (AnimationDrawable) mImgLetter
.getBackground();
loadingAnimation.start();
}
});
}
我的下一个按钮的代码是,
case R.id.btnNext_:
unbindDrawables(findViewById(R.id.imgLetter));
mLetterNum=mLetterNum+1;
getAnimationForLetters(mLetterNum);
我undind绘制方法的代码,
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
终于,我得到异常java.lang.OutOfMemoryError: bitmap size exceeds VM budget
它显示例外这里mImgLetter.setBackgroundResource(resID);
请帮助我。
我加入如下代码清除,
loadingAnimation.stop();
for (int i = 0; i < loadingAnimation.getNumberOfFrames(); ++i){
Drawable frame = loadingAnimation.getFrame(i);
if (frame instanceof BitmapDrawable) {
((BitmapDrawable)frame).getBitmap().recycle();
}
frame.setCallback(null);
}
loadingAnimation.setCallback(null);
它是为仅次于上或下一个动画移动到第二个动画,第二次previous.First时间点击做工精细,如果我以前的按钮,我得到了点击异常像,
Canvas: trying to use a recycled bitmap android.graphics.Bitmap
请帮助我。
我的图像大小为290x330.I认为这不是问题 – 2012-03-06 10:22:51