Android imageview OutOfMemoryError异常:尝试缓存已调整大小的图像以避免异常
我已经阅读了所有outofmemoryerror线程,我知道我正在尝试调整大小以适应大多数图像。我正在我的服务器上存储这些图像,最大大小为250x250。我正在尝试将它们加载到列表中。我已经实现了一个缓存系统,它工作得很好。问题是,我正在缓存来自服务器的图像大小,每次从缓存中提取图像时,我仍在调整图像大小 我想在将图像放入缓存之前调整其大小。我正在使用xml调整列表中图像的大小Android imageview OutOfMemoryError异常:尝试缓存已调整大小的图像以避免异常,android,caching,imageview,out-of-memory,Android,Caching,Imageview,Out Of Memory,我已经阅读了所有outofmemoryerror线程,我知道我正在尝试调整大小以适应大多数图像。我正在我的服务器上存储这些图像,最大大小为250x250。我正在尝试将它们加载到列表中。我已经实现了一个缓存系统,它工作得很好。问题是,我正在缓存来自服务器的图像大小,每次从缓存中提取图像时,我仍在调整图像大小 我想在将图像放入缓存之前调整其大小。我正在使用xml调整列表中图像的大小 <ImageView android:id="@+id/img_user" android:layout_wid
<ImageView android:id="@+id/img_user" android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/noimgsmall"
android:scaleType="fitCenter"/>
如何计算要缓存的图像的大小?我最后做的是将图像调整为实际的缩放大小,然后缓存。没有更多的内存问题。避免在listview中重新调整大小
Drawable cachedImage = null;
cachedImage = imageLoader.loadImage(
store.getLogoUrl(),
new ImageThreadLoader.ImageLoadedListener() {
public void imageLoaded(Drawable imageBitmap) {
View itemView = parent.getChildAt(position -
((ListView) parent).getFirstVisiblePosition());
if (itemView == null) {
return;
}
ImageView img = (ImageView)
itemView.findViewById(R.id.img_user);
if (img == null) {
return;
}
img.setImageDrawable(imageBitmap);
}
}
);
logoImageView.setImageDrawable(cachedImage);