我在我的应用程序中使用以下配置。我们有很多列表屏幕,我们使用智能适配器通过UIL加载图像。我正在使用以下代码进行UIL配置。我们在崩溃日志中遇到了很多OutOfMemoryError。请告诉我配置错误
private static final int MB = 1024 * 1024;
private static final int MEMORY_CACHE_SIZE = (int) 1.5 * MB;
private static final int DISK_CACHE_SIZE = 15 * MB;
private com.nostra13.universalimageloader.core.ImageLoader imageLoader;
public UniversalImageLoader(Context context)
{
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).build();
File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration.Builder configBuilder = new ImageLoaderConfiguration.Builder(context);
configBuilder.threadPriority(1);
if(BuildConfig.DEBUG)
{
configBuilder.writeDebugLogs();
}
configBuilder.denyCacheImageMultipleSizesInMemory();
configBuilder.defaultDisplayImageOptions(defaultOptions);
configBuilder.memoryCache(new LruMemoryCache(MEMORY_CACHE_SIZE));
try
{
configBuilder.diskCache(new LruDiskCache(cacheDir, new HashCodeFileNameGenerator(), DISK_CACHE_SIZE));
}
catch(IOException e)
{
configBuilder.diskCacheSize(DISK_CACHE_SIZE);
}
imageLoader = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
imageLoader.init(configBuilder.build());
imageLoader.handleSlowNetwork(true);
}
答案 0 :(得分:0)
public void initImageLoader(Context context) {
// UNIVERSAL IMAGE LOADER SETUP
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.mipmap.save)
.showImageOnFail(R.mipmap.save).resetViewBeforeLoading()
.cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new FadeInBitmapDisplayer(300)).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.discCacheSize(100 * 1024 * 1024).build();
ImageLoader.getInstance().init(config);
// END - UNIVERSAL IMAGE LOADER SETUP
}