Glide详解

2018-09-20  本文已影响0人  kjy_112233

一、Glide使用

(1)在build.gradle中添加依赖

dependencies {
    compile 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

(2)Glide方法

        Glide.with(this)
                .load(imageUrl)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .placeholder(R.mipmap.ic_launcher)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .fallback(R.drawable.ic_launcher_s)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .error(R.drawable.ic_launcher_s)
                .into(imageView);

        Glide.with(this)
                .load(imageUrl)
                .error(Glide.with(this).load(imageUrl))
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .override(800, 800)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .thumbnail(0.1f)//加载图片百分比缩略图
                .into(imageView);

        Glide.with(this)
                .load(imageUrl)
                .thumbnail(Glide.with(this).load(thumbnailUrl))//缩略图的url
                .into(imageView);

        Glide.with(this)
                .load(imageUrl)
                .thumbnail(Glide.with(this).load(imageUrl).override(800, 800))//同一个url,设置图片尺寸
                .into(imageView);


        Glide.with(this)
                .load(imageUrl)
                .fitCenter()
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .circleCrop()
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .centerCrop()
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .onlyRetrieveFromCache(true)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .skipMemoryCache(true)
                .into(imageView);
        Glide.with(this)
                .load(imageUrl)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
        Glide.with(this)
                .asBitmap()
                .load(imageUrl)
                .into(imageView);
        Glide.with(this)
                .asGif()
                .load(imageUrl)
                .into(imageView);
        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.ic_launcher_s)
                .skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.ALL);


        Glide.with(this)
                .load(imageUrl)
                .apply(requestOptions)
                .into(imageView);
        Glide.get(this).clearDiskCache();
        Glide.get(this).clearMemory();

Glide源码详解

上一篇 下一篇

猜你喜欢

热点阅读