使用ImageLoader 图片处理框架
//得到ImageLoader 实例
ImageLoader imageLoader imageLoader = ImageLoader.getInstance();
初始化
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));
//显示图片
imageLoader.displayImage(imageUrl, imageview, options, animateFirstListener);
//设置图片圆角
public static DisplayImageOptions getOptions() {
DisplayImageOptions options;
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.mini_avatar_shadow)// 设置图片在下载期间显示的图片
.showImageForEmptyUri(R.drawable.mini_avatar_shadow)// 设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.mini_avatar_shadow)// 设置图片加载/解码过程中错误时候显示的图片
.cacheInMemory(true)// 是否緩存都內存中
.cacheOnDisc(true)// 是否緩存到sd卡上
// displayer 为设置显示图片圆角
//RoundedBitmapDisplayer(20) 中的值为设置圆角的幅度,RoundedBitmapDisplayer 中的值
//越大显示在UI中的图片圆角幅度越大
.displayer(new RoundedBitmapDisplayer(20)).build();
return options;
}
缓存的清理:
缓存的清理可以按需求来定,可以再每个Activity的生命周期函数onDestroy中清理也可以单独设置让用户自行清理。
//清除缓存
@Override
public void onDestroy() {
super.onDestroy();
imageLoader.clearMemoryCache();
imageLoader.clearDiskCache();
}