连接:https://www.cnblogs.com/xueqiang911226/p/8056739.html
1,解决Glide加载Gif非常慢问题
1
Glide.with(MainActivity.this).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
为其添加缓存策略,其中缓存策略可以为:Source及None,None及为不缓存,Source缓存原型.如果为ALL和Result就不行
2,加载第一贞:
1
Glide.with(context).load(gifUrl).asBitmap().into(imageViewGifAsBitmap);
3,控制动画次数:
1
Glide.with(this).load(getResource()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(new GlideDrawableImageViewTarget(imageView, 1));
4,GIF 时间:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Glide.with(FirstActivity.this)
.load(file)
.asGif()
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.listener(new RequestListener<File, GifDrawable>() {
@Override
public boolean onException(Exception e, File model, Target<GifDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(final GifDrawable resource, File model, Target<GifDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
new Thread(new Runnable() {
@Override
public void run() {
int duration = 0;
try {
GifDrawable gifDrawable = (GifDrawable) resource;
GifDecoder decoder = gifDrawable.getDecoder();
for (int i = 0; i < gifDrawable.getFrameCount(); i++) {
duration += decoder.getDelay(i);
}
mGifAdTime = duration;
} catch (Throwable e) {
}
}
}).start();
return false;
}
})
.into(mAdImg);