事实上,我的应用程序使用大约80mb,并且往往会在旧设备上崩溃并耗尽内存。我想我已尽我所能:配置低功耗和实现的视图。如前面有关StackOverflow的帖子和https://github.com/nostra13/Android-Universal-Image-Loader#useful-info
中所述我的应用程序包含一个包含10个图像的ListView(每个图像都是从服务器加载的,大小约为100kb,1000x1000像素(但在图像之间有所不同))。
现在我倾向于认为,我可能在我的代码中实现了一些错误:
public class CustomAdapter extends ArrayAdapter<ImageObject>{
private List<ImageObject> images;
private Context context;
private int resourceID;
private DisplayImageOptions options;
private ImageLoaderConfiguration config;
private ImageLoader imageLoader;
public CustomAdapter(Context context, int resourceID, List<ImageObject> images) {
super(context, resourceID, images);
this.context = context;
this.images = images;
this.resourceID = resourceID;
options = new DisplayImageOptions.Builder()
.bitmapConfig(Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)
.delayBeforeLoading(0)
.build();
config = new ImageLoaderConfiguration.Builder(context)
.threadPoolSize(2)
.memoryCache(new WeakMemoryCache())
.defaultDisplayImageOptions(options)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if(view == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(resourceID, null);
holder = new ViewHolder();
holder.image = (ImageView) view.findViewById(R.id.imageview);
holder.hasAnimated = false;
view.setTag(holder);
}else {
holder = (ViewHolder) view.getTag();
}
ImageObject image = images.get(position);
if(image != null){
ImageAware imageAware = new ImageViewAware(holder.image, false);
if(!holder.hasAnimated){
imageLoader.displayImage(image.getUrl(), imageAware, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.animation);
holder.image.setAnimation(animation);
animation.start();
}
});
holder.hasAnimated = true;
}else{
imageLoader.displayImage(image.getUrl(), imageAware);
}
}
return view;
}
static class ViewHolder {
ImageView image;
Boolean hasAnimated;
}
}
有什么明显的,我做错了吗?或者显然是为了改善?
编辑:为什么EXACTLY_STRETCHED消费超过完全?似乎只是在使用完全正确时使用某些图像(在ImageView中使用android:scaleType =“centerCrop”)。
谢谢和最诚挚的问候。