When loading an XML layout with a lot of ImageViews, I'm getting an OutOfMemoryError
. Unlike most people who seem to be reporting this error, my layout just loads ImageViews directly from the Drawable folder by putting this XML attribute on each ImageView (of which there are about 50 in the layout):
android:src="@drawable/image"
Then, I load the layout all at once in the Activity's call to OnCreate.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
}
Even following some common tricks (namely setting LargeHeap to true and reducing the size of the image), I still can't avoid this error. I can only assume that it's a result of the combination of the image being a few KB and it being loaded into about 50 ImageViews.
I can't reduce the size of the image any further and I can't reduce the number of ImageViews it's loaded into. Because I'm loading directly from the Drawable folder, it also doesn't seem like the tips in Android's guide to displaying bitmaps efficiently or a third-party image-loading tool like Picasso are very likely to help.
How can I avoid this error?