我有九张图片需要在一个活动开始时加载,并且出现OutOfMemory异常问题。起初我直接在xml设置它的src中加载它们。因此,越来越java.lang.OutOfMemory后,我意识到,也许我需要更有效地加载照片,我创造了这个循环在活动开始时要执行:OutOfMemory问题加载几张图片
for(int i=0;i<9;i++){
String background = "background"+(i+1);
int idDrawable = getResources().getIdentifier(background, "drawable", getPackageName());
int idPicture = getResources().getIdentifier(background, "id", getPackageName());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), idDrawable, options);
options.inJustDecodeBounds = false;
ImageView image = (ImageView) findViewById(idPicture);
image.setImageBitmap(BitmapFactory.decodeResource(getResources(), idDrawable, options));
}
但我仍然有同样的问题,内存不足,关于我在做什么错误的任何想法? googeling的
负载图像异步删除此行 –