Android图片加载缓存库<2>

Glide:快速和高效的Android平台多媒体资源管理库

Glide 是一个android平台上的快速和高效的开源的多媒体资源管理库, 提供 多媒体文件的压缩,内存和磁盘缓存, 资源池的接口

Glide 支持获取,解压展示视频, 图像和GIFs, Glide有一个可弹性的api可以让开发者自定义网络栈技术, 默认使用HttpUrlConnection , 你可以替换为 Google’s Volley或者 OkHttp

Glide 开始的目的是提供一个快速和平滑展示图片列表, 但是Glide对你需要拉取, resize 和展示远程的图片这些场景都是很管用的.

或者使用Gradle

repositories {
  mavenCentral()
}

dependencies {
    compile 'com.github.bumptech.glide:glide:3.3.+'
    compile 'com.android.support:support-v4:19.1.0'
}

Maven

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>glide</artifactId>
  <version>3.3.1</version>
  <type>aar</type>
</dependency>
<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>support-v4</artifactId>
  <version>r7</version>
</dependency>

使用
简单的例子:

// For a simple view:
@Override
public void onCreate(Bundle savedInstanceState) {
    ...

    ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

    Glide.with(this).load("http://goo.gl/h8qOq7").into(imageView);
}

// For a list:
@Override
public View getView(int position, View recycled, ViewGroup container) {
    final ImageView myImageView;
    if (recycled == null) {
        myImageView = (ImageView) inflater.inflate(R.layout.my_image_view,
                container, false);
    } else {
        myImageView = (ImageView) recycled;
    }

    String url = myUrls.get(position);

    Glide.with(myFragment)
        .load(url)
        .centerCrop()
        .placeholder(R.drawable.loading_spinner)
        .crossFade()
        .into(myImageView);

    return myImageView;
}

Volley
如果你想使用Volley

Gradle

dependencies {
    compile 'com.github.bumptech.glide:volley-integration:1.0.+'
    compile 'com.mcxiaoke.volley:library:1.0.+'
}

Maven:

<dependency>
    <groupId>com.github.bumptech.glide</groupId>
    <artifactId>volley-integration</artifactId>
    <version>1.0.1</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>com.mcxiaoke.volley</groupId>
    <artifactId>library</artifactId>
    <version>1.0.5</version>
    <type>aar</type>
</dependency>

然后在你的Activity或者程序中,注册Volley为基本模块

public void onCreate() {
  Glide.get(this).register(GlideUrl.class, InputStream.class,
        new VolleyUrlLoader.Factory(yourRequestQueue));
  ...
}

OkHttp

Gradle:

dependencies {
    compile 'com.github.bumptech.glide:okhttp-integration:1.0.+'
    compile 'com.squareup.okhttp:okhttp:2.0.+'
}

Maven:

<dependency>
    <groupId>com.github.bumptech.glide</groupId>
    <artifactId>okhttp-integration</artifactId>
    <version>1.0.1</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp</groupId>
    <artifactId>okhttp</artifactId>
    <version>2.0.0</version>
    <type>jar</type>
</dependency>

然后在你的Activity或者程序中,注册Volley为基本模块

public void onCreate() {
  Glide.get(this).register(GlideUrl.class, InputStream.class,
        new OkHttpUrlLoader.Factory(yourOkHttpClient));
  ...
}

github地址 https://github.com/bumptech/glide

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值