目录
1. Glide API
Glide中文文档:https://muyangmin.github.io/glide-docs-cn/#glide-v4-android-english-tip
Glide API:https://muyangmin.github.io/glide-docs-cn/javadocs/480/index.html
2. Glide导入包
implementation 'com.github.bumptech.glide:glide:4.8.0'
3. Glide 7种加载图片方式
- load(String path) :通过http路径
ImageView imageView = (ImageView) findViewById(R.id.img_show); String imgUrl1 = "https://i.imgur.com/CqmBjo5.jpg"; Glide.with(context).load(imgUrl1).into(imageView);
- load(Uri uri): 通过Url
ImageView imageView = (ImageView) findViewById(R.id.img_show); String imgUrl2 = "https://i.imgur.com/0gqnEaY.jpg"; Glide.with(context).load(Uri.parse(imgUrl2)).into(imageView);
- load(File file) 加载手机本地图片
ImageView imageView = (ImageView) findViewById(R.id.img_show); String imgUrl3 = Environment.getExternalStorageDirectory().getPath() + "/img3.jpg"; File file = new File(imgUrl3); Glide.with(context).load(file).into(imageView);
- load(file:///android_asset/...) 加载assets中的图片
ImageView imageView = (ImageView) findViewById(R.id.img_show); Glide.with(context).load("file:///android_asset/img5.jpg").into(imageView);
- load(int resourceId) 通过ResourceId加载
ImageView imageView = (ImageView) findViewById(R.id.img_show); Glide.with(context).load(R.mipmap.img1).into(imageView);
- load(Bitmap) 加载Bitmap位图
ImageView imageView = (ImageView) findViewById(R.id.img_show); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.mipmap.img_error); Glide.with(context).load(bitmap).into(imageView);
- load(Drawable) 加载Drawable可绘制图片
ImageView imageView = (ImageView) findViewById(R.id.img_show); Drawable drawable = getResources().getDrawable(R.mipmap.img1); Glide.with(context).load(drawable).into(imageView);
4. 取消加载
Glide.with(context).clear(imageView);