我有一个ListView,每个项目最多可以有10个图标。如果我上下滚动ListView,我会强制关闭,说Bitmap大小超过VM Budget,而且我已经没有内存了。我在这里阅读有关回收Bitmaps的信息,所以我写了一个方法,它回收了我的Bitmaps。问题是滚动速度很慢。这是我的功能:
private void recycleBmpsFromConvertView(View convertView){
if (convertView != null && convertView instanceof LinearLayout) {
LinearLayout iconArea = (LinearLayout)convertView;
for (int i = 0; i < iconArea.getChildCount(); i++) {
View v = iconArea.getChildAt(i);
if (v instanceof LinearLayout) {
LinearLayout row = (LinearLayout) v;
for (int j = 0; j < row.getChildCount(); j++) {
View candidate = row.getChildAt(j);
if (candidate instanceof ImageView) {
ImageView image = (ImageView) candidate;
Drawable d = image.getDrawable();
Bitmap bmp = null;
if (d instanceof SvgDrawable) {
SvgDrawable svg = (SvgDrawable) d;
bmp = svg.getBitmap();
} else if (d instanceof BitmapDrawable) {
BitmapDrawable bmpd = (BitmapDrawable) d;
bmp = bmpd.getBitmap();
}
if (bmp != null) {
bmp.recycle();
bmp = null;
}
}
}
}
}
}
System.gc();
}
只要我的convertView不为null,我就会尝试删除位图。我的方法有更快的方法吗?
答案 0 :(得分:-1)
删除回收