Glide 集成 OkHttp2.x 、OkHttp3.x 和 Volley

由于 Android 6.0 以后废除了 httpclient , glide 加载网络图片需要自己集成网络访问库了

一 添加 glide 依赖

在 build.gradle 添加

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

二 集成网络访问库

1 集成 okhttp2.x

在 build.gradle 添加

dependencies {
    ...
    // 这个是用来对接 okhttp 2.x 的
    compile 'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'
    // okhttp 2.x 的依赖
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    ...
}

然后在 AndroidManifest.xml 文件添加

<meta-data
    android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule"
    android:value="GlideModule" />

2 集成 okhttp 3.x

在 build.gradle 添加

dependencies {
    ...
    // 这个是用来对接 okhttp 3.x 的
    compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
    // okhttp 3.x 的依赖
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    ...
}

然后在 AndroidManifest.xml 文件添加

<meta-data
    android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
    android:value="GlideModule" />

3 集成 Volley

在 build.gradle 添加

dependencies {
    ...
    // 这个是用来对接 volley 的
    compile 'com.github.bumptech.glide:volley-integration:1.4.0@aar'
    // volley 的依赖
    compile 'com.mcxiaoke.volley:library:1.0.8'
    ...
}

然后在 AndroidManifest.xml 文件添加

<meta-data
    android:name="com.bumptech.glide.integration.volley.VolleyGlideModule"
    android:value="GlideModule" />
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值