配置
在AndroidManifest。xml中配置如下
<!--访问网络连接,可能产生GPRS流量 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!--获取网络信息状态,如当前的网络连接是否有效 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
在build.gradle中配置:
implementation ("com.github.bumptech.glide:glide:4.11.0")
使用方法
为relativeLayout设置背景图 最新版本方法!(旧方法被弃用)
relativeLayout = findViewById(R.id.relative_main);
Glide.with(this)
.load("https://b-ssl.duitang.com/uploads/item/201301/14/20130114163153_eHHNS.thumb.400_0.gif")
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
// Do something with the Drawable here
relativeLayout.setBackground(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
// 从任何视图中删除onResourceReady中提供的Drawable,并确保不保留对它的引用。
}
});
如果有确定的布局 不需要其他操作:
Glide.with(imageView.context).load(imageData).centerCrop().into(imageView)