Android Glide使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ElevenDGQ/article/details/81283435

https://muyangmin.github.io/glide-docs-cn/doc/download-setup.html

https://github.com/bumptech/glide

https://github.com/bumptech/glide/tree/v3.7.0

AS 引用

dependencies {

                           compile 'com.github.bumptech.glide:glide:3.7.0'

}

// 加载本地图片

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);

Glide的使用:

Glide.with(this)

.load(url)  //需要加载的资源

.asGif() //设定图片格式 gif jpg

.placeholder(R.drawable.loading) //加载中站位图

.error(R.drawable.error)  //加载失败站位图

.diskCacheStrategy(DiskCacheStrategy.NONE)  //不取缓存

.override(100, 100) //指定图片大小

.into(imageView);

主线程中 传入当前页面的上下文 Glide随当前页面的生命周期而动

非主线程中 调用Application的上下文 。

Glide详细解读http://blog.csdn.net/guolin_blog/article/details/53759439  大神写的足够好

  • DiskCacheStrategy.NONE: 表示不缓存任何内容。
  • DiskCacheStrategy.SOURCE: 表示只缓存原始图片。
  • DiskCacheStrategy.RESULT: 表示只缓存转换过后的图片(默认选项)。
  • DiskCacheStrategy.ALL : 表示既缓存原始图片,也缓存转换过后的图片。

.listener(new RequestListener<String, GlideDrawable>() {

@Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false;

} @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

return false;

} }) 

.into(new SimpleTarget<GlideDrawable>() {
    @Override
    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
        //mIvMyInfoHead.setImageDrawable(resource);
    }
});

 https://github.com/wasabeef/glide-transformations 。图片变化

猜你喜欢

转载自blog.csdn.net/ElevenDGQ/article/details/81283435