我正在制作一个Android应用程序,我在报告“内存不足异常”时遇到了一些问题,在网上多次搜索后,我发现 android:background 正在将背景图像加载到内存中。
所以我将删除我的 XML 文件中的所有“android:background”声明,并将其替换为:
background = new BitmapDrawable(getResources(),ImageFactoring.decodeSampledBitmapFromResource(getResources(), R.drawable.catalogue_button_poeles_bois, mMaxButton_Cheminees.getLayoutParams().width, mMaxButton_Cheminees.getLayoutParams().height));
mMaxButton_Cheminees.setBackgroundDrawable(background);
在此之前,我想知道“setBackgroundDrawable”是否正在将图片加载到内存中?