Android Glide框架简析:

来源:互联网 发布:万网域名注册流程图 编辑:程序博客网 时间:2024/06/06 12:22

介绍:glide是谷歌官方推荐的图片加载库框架,稳定且轻量好用,其他框架也有,你们可以比较,起码暂时glide最好

配置:不需要什么jar包,直接在新版AS build.gradle中添加依赖就可以

dependencies {    compile 'com.github.bumptech.glide:glide:3.7.0'}

权限:若需要获取网络或SD卡资源,这个就需要

 <uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

方法:

                         Glide                        .with(this)//当前位置                        .load(Images.imageThumbUrls[3])//资源路径                        .into(iv6);//加载到imageview

实例:

//加载项目图片        Glide.with(this).load(R.mipmap.ic_launcher).into(iv1);        //加载SD卡图片        Glide.with(this).load( / storage / emulated / aile / image / a.png).into(iv1);        //加载网络图片        Glide.with(this).load("http://.../20.jpg").into(iv1);        //使用圆形变换        Glide.with(this)                .load("http://.../20.jpg")                .placeholder(R.mipmap.ic_launcher)                .bitmapTransform(new CropCircleTransformation(MainActivity.this))                .into(iv1);        //椭圆形变换        Glide.with(this)                .load("http://.../20.jpg")                .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存图片                .bitmapTransform(new RoundedCornersTransformation(this, 30, 0, RoundedCornersTransformation.CornerType.ALL))                .into(iv1);        //初始化图片和加载错误时的图片        Glide.with(this).load("http://.../20.jpg")                .placeholder(R.mipmap.ic_launcher)                .priority(Priority.IMMEDIATE)//指定加载的优先级,优先级越高越优先加载                .error(R.mipmap.ic_launcher).centerCrop().into(iv1);        //用原图的缩略图        Glide                .with(this)                .load("http://.../20.jpg")                .thumbnail(0.1f)                .into(iv1);        //灰度处理        Glide.with(this).load("http://.../20.jpg").bitmapTransform(new GrayscaleTransformation(this)).into(iv1);        //加载gif图片        Glide.with(this).load("http://../adf.gif").asGif().into(iv1);        //拉伸填充Glide.with(this).load("http://.../20.jpg").placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).centerCrop().into(iv1);    }

绿色的图片

0 0