3 回答

TA貢獻1783條經驗 獲得超4個贊
試試
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
演示
@GlideModule
public class FlickrGlideModule extends AppGlideModule {
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
super.applyOptions(context, builder);
builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
}
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
@NonNull Registry registry) {
registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory());
}
// Disable manifest parsing to avoid adding similar modules twice.
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
讀 AppGlideModule
供參考
你的loadImage方法將是
public static void loadImage(Context ctx,RequestOptions glideRequests, String url, ImageView imageView) {
loadImage(ctx,glideRequests, url, imageView, DiskCacheStrategy.ALL);
}
public static void loadImage(Context ctx,RequestOptions glideRequests, String url, ImageView imageView, DiskCacheStrategy diskCacheStrategy) {
Glide.with(ctx)
.applyDefaultRequestOptions(requestOptions.placeholder(R.drawable.ic_stub).error(R.drawable.ic_stub))
.asBitmap()
.load(url).into(imageView);
}
然后
ImageUtil.loadImage(context,options,obj.getPhotoUrl(),avatarImageView);

TA貢獻1853條經驗 獲得超18個贊
似乎正在進行很好的討論。別擔心。我有解決方案。
按照步驟:
添加依賴項如下(我使用的是最新版本)
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
創建包(因為我一直使用結構化代碼)myglide 并復制/粘貼以下類:
@GlideModule
public class SampleGlideModule extends AppGlideModule {
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
super.applyOptions(context, builder);
}
}
現在您可以按CTRL+F9或您可以單擊菜單Make Project中的Build選項。它將自動生成一個文件(您可以通過按 CTRL 并將鼠標懸停在 File 中的 ClassName 上來查看。)
final class GeneratedAppGlideModuleImpl extends GeneratedAppGlideModule {
private final SampleGlideModule appGlideModule;
....
}
現在您可以非常輕松地使用GlideApp類。
如果您有任何錯誤,請隨時與我聯系。
希望它會幫助你。我一如既往地喜歡 Glide。<3

TA貢獻1859條經驗 獲得超6個贊
嘗試這個
進口Glide在增加的gradle這個
compile 'com.github.bumptech.glide:glide:3.8.0'
然后使用此代碼
Glide.with(context)
.load(url)
.placeholder(R.drawable.ic_male)
.error(R.drawable.imagenotfound)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// log exception
Log.e("TAG", handle error case", e);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
Log.e("TAG", handle success case here", e);
return false;
}
})
.into(avatarImageView);
添加回答
舉報