.load(url)
.apply(options2)
.into(mImage);
- 指定加载格式GIF
Glide.with(this.getApplicationContext())
.load(“file:///android_asset/jdfw.gif”)
.into(mImage);
- 获取gif第一帧
/**
-
注意:在Glide 3中的语法是先load()再asBitmap()的,
-
而在Glide 4中是先asBitmap()再load()的
-
如果写错了顺序就肯定会报错了
*/
Glide.with(this.getApplicationContext())
//.asBitmap()//强制指定加载静态图片
//.asGif()//强制指定加载动态图片
//.asFile()//强制指定文件格式的加载
.asDrawable()//强制指定Drawable格式的加载
.load(“file:///android_asset/jdfw.gif”)
.into(mImage);
- 回调与监听
/**
- 回调与监听
*/
SimpleTarget simpleTarget = new SimpleTarget() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
mImage.setImageDrawable(resource);
}
};
Glide.with(this.getApplicationContext())
.load(url)
.into(simpleTarget);
- 预加载后显示
预加载
Glide.with(this)
.load(“https://unsplash.it/200/200?random&22”)
.preload();
预加载后显示
Glide.with(this.getApplicationContext())
.load(“https://unsplash.it/200/200?random&22”)
.into(mImage);
- submit()方法:类似Glide3中的downloadOnly
new Thread(new Runnable() {
@Override
public void run() {
try {
final Context context = getApplicationContext();
FutureTarget target = Glide.with(context)
//.asDrawable()
.asFile()
.load(url)
.submit();
//final Drawable drawable = target.get();
final File imageFile = target.get();
runOnUiThread(new Runnable() {
@Override
public void run() {
mTextview.setText(imageFile.getPath());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
- listener()方法
Glide.with(this.getApplicationContext())
.load(url)
.listener(new RequestListener() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResour