我已经创建了印地语视频歌曲应用程序,但是视频缩略图无法显示在视频列表中。(已加载单个图像,但无法加载多个图像阵列。)
使用多个图像加载器库,但不加载图像:
滑行:
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
Glide .with(viewHolder.icon_1.getContext())
.load(((AppModelicon) this.b.get(i)).getThumnail())
.into(viewHolder.icon_1) ;
Glide.with(MainActivity.this)
.load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
.placeholder(R.drawable.ic_menu_camera)
.error(R.drawable.ic_menu_gallery)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
// log exception
Log.e("TAG", "Error loading image", e);
return false; // important to return false so the error placeholder can be placed
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(viewHolder.icon_1);
毕加索:
implementation 'com.squareup.picasso:picasso:2.+'
Picasso.get()
.load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
.resize(50, 50)
.centerCrop()
.into(viewHolder.icon_1);
使用带有滑行的请求管理器:
RequestManager requestManager = Glide.with(a)
.applyDefaultRequestOptions(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.applyDefaultRequestOptions(RequestOptions.placeholderOf(R.drawable.ic_menu_camera));
requestManager
.applyDefaultRequestOptions(RequestOptions.skipMemoryCacheOf(true));
requestManager.load(pathToFile)
.into(viewHolder.icon_1);
后台任务方法使用:
String pathToFile = this.b.get(i).getThumnail();
DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(viewHolder.icon_1);
downloadTask.execute(pathToFile);
public class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageWithURLTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String pathToFile = urls[0];
Bitmap bitmap = null;
try {
InputStream in = new java.net.URL(pathToFile).openStream();
bitmap = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return bitmap;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
请帮助我解决此问题。
不传递MainActivity.this作为上下文,它总是错误的。。
尝试一下
//in activity
Glide.with(this)
.load("https://pbs.twimg.com/profile_images/1123379185764917248/On9ZnfVh.png")
.into(imageView)
//in Fragments
Glide.with(view.context)
.load("url")
.into(imageView)
用您自己的替换.load(“ url”)和“ imageView”。
删除此行中的依赖项
annotationProcessor'com.github.bumptech.glide:compiler:4.10.0'