在我的应用程序中,我有一个ImageViews列表。这些ImageView的大小是1024x512。在XML中,这是每个ImageView的是如何定义的:将位图加载到imageView的正确方法是什么
<ImageView
android:id="@+id/imageView3"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/pic" />
,这是我如何设置每个的ImageView位在getView在ArrayAdapter:
File picToLoad = new File(localPhotosUrl.get(0));
byte[] array= null;
try {
array= org.apache.commons.io.FileUtils.readFileToByteArray(picToLoad);
System.gc();
Bitmap bitmap = BitmapFactory.decodeByteArray(array, 0, array.length);
holder.imgIcon.setImageBitmap(bitmap);
}
现在发现,我是从加载图像SD卡是1024x512,但ImageView是75x75。这种方式是正确的吗?意义设置图像位图全图还是内存消耗?我应该在调用setImageBitmap之前将图像大小调整为75x75,否则它不会做任何更改?
请阅读下面的答案,但也不应该调用'System.gc()',这是一个糟糕的做法(除非非常特殊的情况),android处理垃圾收集 –
为什么这是不好的做法?如果有的话它会收集一些垃圾early.I也认为,显式调用GC并不能确保垃圾将被收集 – Libathos
阅读[this](https://stackoverflow.com/questions/2414105/why-is-it-a -bad-practice-to-call-system-gc)和[this](http://bugs.java.com/view_bug.do?bug_id=6668279) –