我正在尝试使用Glide库将gif加载到ImageView中。 Gif图片在Raw文件夹中。下面是代码:
Glide.with(mContext)
.asGif()
.load(R.raw.tenor)
.listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
Log.d("Fragment::","onLoadFailed::" + e.getMessage());
Log.d("Fragment::","onLoadFailed::" + e.getCauses());
Log.d("Fragment::","onLoadFailed::" + e.getRootCauses());
return false;
}
@Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
Log.d("Fragment::","onResourceReady::" + resource.getFrameCount());
return false;
}
})
.into(mainIv);
但是它没有加载。我有什么想念的吗?它没有给出失败的日志。
答案 0 :(得分:0)
就我而言,这项工作:
DrawableImageViewTarget target = new DrawableImageViewTarget(myImageView);
Glide.with(context)
.load(R.drawable.camera_rotate)
.into(target);
我的可绘制文件夹中的gif。
答案 1 :(得分:0)
删除asGif,代码如下:
Glide.with(mContext)
.load(R.raw.tenor)
.listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
Log.d("Fragment::","onLoadFailed::" + e.getMessage());
Log.d("Fragment::","onLoadFailed::" + e.getCauses());
Log.d("Fragment::","onLoadFailed::" + e.getRootCauses());
return false;
}
@Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
Log.d("Fragment::","onResourceReady::" + resource.getFrameCount());
return false;
}
})
.into(mainIv);