1. 使用glide加载图片到imageview
链接推荐
https://blog.csdn.net/hanxiongwei/article/details/86625333 这个博客里写了关于glide的基础知识,以及加载图片到imageview
2.使用glide加载图片到非imageview
方式1.在监听器中加载背景图片
Glide.with(context)
.load(图片路径)
.listener(new RequestListener() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Targettarget, boolean isFirstResource) {
//失败加载的默认图片
activityLayout.setBackground(getResources().getDrawable(R.drawable.defaultbackground));
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Targettarget, DataSource dataSource, boolean isFirstResource) {
//成功加载的图片
activityLayout.post(()->{
activityLayout.setBackground(resource);
});
return true;
}
})
.into(1024, 600);
方式二 通过 SimpleTarget
Glide.with(context)
.load(图片路径)
.into(new SimpleTarget() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition super Drawable> transition) {
activityLayout.setBackground(resource);
}
});
如果想要深入研究就看下郭神的glide系列把
https://blog.csdn.net/sgiceleo/article/details/64440783