我有一個GridView必須加載大量的項目(約300)與圖像,這些圖像使用UniversalImageLoader從互聯網下載。我的問題是關於內存(OutOfMemoryException)。圖像管理大型GridView(OutOfMemoryException)
這是我的適配器代碼:
public View getView(int position, View convertView, ViewGroup viewGroup) {
View v = convertView;
ViewHolder vh = null;
if (v == null) {
v = View.inflate(context, R.layout.item_gridview, null);
vh = new ViewHolder();
vh.imageView = (ImageView) v.findViewById(R.id.imagenCategoria);
v.setTag(vh);
TextView nombreElemento = (TextView) v.findViewById(R.id.nombreElemento);
nombreElemento.setText(elementos.get(position).getTitulo());
TextView infoElemento = (TextView) v.findViewById(R.id.infoElemento);
infoElemento.setText(elementos.get(position).getCalidad()+" "+elementos.get(position).getLenguaje()+" "+elementos.get(position).getAnho());
}else {
vh = (ViewHolder)v.getTag();
}
ImageAware imageAware = new ImageViewAware(vh.imageView, false);
String coverUrl = elementos.get(position).getUrlCover();
if(coverUrl!=null && !coverUrl.equals(""))imageLoader.displayImage(coverUrl, imageAware);
return v;
}
private class ViewHolder {
ImageView imageView;
}
這就是我的ImageLoader的對象的配置:
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true)
.cacheInMemory(true)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Config.RGB_565) .resetViewBeforeLoading(true)
.build();
ImageLoaderConfiguration configs = new ImageLoaderConfiguration.Builder(
context.getApplicationContext())
.memoryCache(new WeakMemoryCache())
.discCacheSize(104857600)
.defaultDisplayImageOptions(defaultOptions)
.imageDownloader(new HttpClientImageDownloader(c, new DefaultHttpClient(manager, params))).threadPoolSize(10).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(configs);
有誰知道解決的辦法?最好。
您可以在光盤或清除緩存onLowMemory()緩存調用@覆蓋 \t公共無效onLowMemory(){ \t \t ImageLoader.getInstance清除緩存() ().clearMemoryCache(); \t \t super.onLowMemory(); \t} – 2014-09-10 10:37:34