public class GlobalApplication extends Application {
public static ImageLoader imageLoader = ImageLoader.getInstance();
public static DisplayImageOptions options;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
initImageLoader(getApplicationContext());
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_launcher)// 加载等待 时显示的图片
.showImageForEmptyUri(R.drawable.ic_launcher)// 加载数据为空时显示的图片
.showImageOnFail(R.drawable.ic_launcher)// 加载失败时显示的图片
.cacheInMemory().cacheOnDisc() /**
* .displayer(new
* RoundedBitmapDisplayer(20))
**/
.build();
}
public static void initImageLoader(Context context) {
// This configuration tuning is custom. You can tune every option, you
// may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context).threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
//软引用和强引用结合
//FIFOLimitedMemoryCache(先进先出的缓存策略,当超过设定值,先删除最先加入缓存的bitmap)
.memoryCache(new FIFOLimitedMemoryCache(2*1024*1024))
// default为使用HASHCODE对UIL进行加密命名, 还可以用MD5(new Md5FileNameGenerator())加密
//.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
.discCacheSize(50*1024*1024)
.discCacheFileCount(100)
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging() // Not
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
// imageLoader.init(ImageLoaderConfiguration.createDefault(context));
}
}
这是在Application里的配置
public class HeadFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.headfragment,container,false);
ImageView iv = (ImageView) view.findViewById(R.id.head_iv);
Bundle bundle = getArguments();
String headImageUrl = bundle.getString("headImageUrl");
Log.e("headImageUrl", headImageUrl);
GlobalApplication.imageLoader.displayImage(headImageUrl, iv,GlobalApplication.options);
return view;
}
}
这是用到的时候ImageLoader的时候。
但是老是报错,怎么回事啊