- 在ImageLoaderManager类中写一个静态方法,方便调用,不用每次都new对象,减少内存使用
private ImageLoaderManager() {
}
public static ImageLoaderManager getInstance() {
return SingletonHolder.instance;
}
private static class SingletonHolder {
private static ImageLoaderManager instance = new ImageLoaderManager();
}
public void displayImageForCircle(final ImageView imageView, String url,final boolean f) {
Glide.with(imageView.getContext())
.asBitmap()
.load(url)
.apply(initCommonRequestOption())
.into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(final Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(imageView.getResources(), resource);
circularBitmapDrawable.setCircular(f);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
}
@SuppressLint("CheckResult")
private RequestOptions initCommonRequestOption() {
RequestOptions options = new RequestOptions();
options.placeholder(R.mipmap.b4y)
.error(R.mipmap.b4y)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.skipMemoryCache(false)
.priority(Priority.NORMAL);
return options;
}