1,解決Glide加載Gif非常慢問題
Glide.with(MainActivity.this).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
為其添加緩存策略,其中緩存策略可以為:Source及None,None及為不緩存,Source緩存原型.如果為ALL和Result就不行
2,加載第一貞:
Glide.with(context).load(gifUrl).asBitmap().into(imageViewGifAsBitmap);
3,控制動畫次數:
Glide.with(this).load(getResource()).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(new GlideDrawableImageViewTarget(imageView, 1));
4,GIF 時間:
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);
