【发布时间】:2014-10-17 17:00:07
【问题描述】:
我目前正在使用 Picasso 下载这样的图像:
ImageView imageView = (ImageView) rootView.findViewById(R.id.imagePreview);
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Transformation transformation = new Transformation() {
@Override public Bitmap transform(Bitmap source) {
int targetHeight = 500;
double aspectRatio = (double) source.getWidth() / (double) source.getHeight();
int targetWidth = (int) (targetHeight * aspectRatio);
Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
if (result != source) {
// Same bitmap is returned if sizes are the same
source.recycle();
}
return result;
}
@Override public String key() {
return "transformation" + " desiredWidth";
}
};
RequestCreator requestCreator;
Picasso picasso = Picasso.with(context);
requestCreator = picasso
.load(resource)
.transform(transformation)
.skipMemoryCache()
.error(R.drawable.ic_placeholder_ricerca);
我什至调整了图像的大小,但这还不够。问题是我有一个无穷无尽的listView,所以我一直在下载图像,然后内存就会变满。知道如何预防这个问题吗?我想扩大memoryCache(在代码中我也尝试过完全跳过但没有结果),但我不知道该怎么做(网上的代码示例不起作用:()。
【问题讨论】:
标签: android android-image picasso