我正在创建一个 React Native 原生 UI 组件。它是一个图片库,需要从 URL 加载图片。在我的 PageAdapter
中,我正在使用以下代码加载图像,但未加载图像。
Glide.with(context).load(url).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
Log.e("ImageLoader", "Load failed", e);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
Log.i("ImageLoader", "Successfully loaded");
return false;
}
}).override(720, 1280).into(imageView);
onResourceReady
方法总是命中但没有图像正在加载。我该如何解决这个问题?
最佳答案
尝试使用:
Glide.with(context)
.asBitmap()
.load(url)
.into(new CustomTarget<Bitmap>(720,1280) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
imageView.setImageBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
确保你使用的是最新版本
implementation 'com.github.bumptech.glide:glide:4.9.0'
关于android - Glide 图像未加载到 React Native 原生 UI 组件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56805921/