What is 1 glide
glide is an image loading and caching libraries.
2 glide of use
First, add dependencies
implementation 'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
Second, add access to the network
<uses-permission android:name="android.permission.INTERNET" />
3 common methods
3.1 to load various forms of picture ImageView
// 加载本地图片
File file = new File(getExternalCacheDir() + "/image.jpg"); Glide.with(this).load(file).into(imageView); // 加载应用资源 int resource = R.drawable.image; Glide.with(this).load(resource).into(imageView); // 加载二进制流 byte[] image = getImageBytes(); Glide.with(this).load(image).into(imageView); // 加载Uri对象 Uri imageUri = getImageUri(); Glide.with(this).load(imageUri).into(imageView);
3.2 Load picture with a placeholder map
The purpose placeholder figure is not loaded when the picture came out, showing a picture to the user in advance.
Glide.with(this).load(url).placeholder(R.drawable.loading).into(imageView);
3.3 fails to load placed placeholder image
Glide.with(this).load(url).placeholder(R.drawable.loading).error(R.drawable.error) .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制 .into(imageView);