【发布时间】:2013-10-21 11:52:24
【问题描述】:
我有九张图片要在活动开始时加载,但我遇到了 OutOfMemory 异常的问题。起初我将它们直接加载到 xml 设置它的 src。所以在获得 java.lang.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));
}
但我仍然有同样的 OutOfMemory 问题,有什么想法我做错了什么吗?
【问题讨论】:
-
后台线程异步加载图片
标签: java android bitmap out-of-memory