我想以编程方式在linearLayout
中添加几个ImageView
。 但应用程序崩溃超过2个图像。它的错误是OutOfMemoryError。以编程方式添加imageView时OutOfMemoryError
String[] titleImages={"a","b","c","d","e","f","g"};
for (String title : titleImages){
InputStream inputStream = context.getAssets()
.open("titles"+"/"+title);
Drawable drawable = Drawable.createFromStream(inputStream, null);
inputStream.close();
ImageView imageView = new ImageView(_context);
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setImageDrawable(drawable);
//more imageView set properties
LinearLayout shelf=findViewById(R.id.shelf);
//shelf is a LinearLayout
shelf.addView(imageView);
}
使用尝试捕捉。处理内存不足 – 2014-11-25 12:59:02
@AshwinSAshok这是一个错误,没有例外。在大多数情况下,不应该捕获“Error”的子类,而其中的“OutOfMemoryError”。 – aga 2014-11-25 13:01:12