问题
I tried to get this GIF from a URL like this:
Glide.with(context)
.load("http://artfcity.com/wp-content/uploads/2017/07/tumblr_osmx1ogeOD1r2geqjo1_540.gif")
.into(new GlideDrawableImageViewTarget(imageViewBaby) {
@Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim);
imageViewBaby.setImageDrawable(drawable);
imageViewBaby.invalidate();
imageViewBaby.requestLayout();
}
});
But the GIF will not move or start. It's just like an image! How to solve this issue?
回答1:
Try this
Add dependency
implementation 'com.github.bumptech.glide:glide:4.4.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
Gif Loading
Glide.with(this)
.load("http://artfcity.com/wp-
content/uploads/2017/07/tumblr_osmx1ogeOD1r2geqjo1_540.gif")
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.into(imageView);
See this https://github.com/bumptech/glide/issues/2471
回答2:
As android doesnot support gif files, you can use webview to display the gif file.
回答3:
Please use .asGif()
to load gif images inside your ImageView
:
Glide.with(context)
.load(gifUrl)
.asGif()
.diskCacheStrategy(DiskCacheStrategy.SOURCE).override(200, 200)
.into(((GifViewHolder) holder).gifImageView);
来源:https://stackoverflow.com/questions/48013012/load-gif-from-url