Android开源项目-Glide

本文介绍了Glide这一由Google维护的Android图片加载库。通过对比Universal-Image_loader、Fresco及Picasso等库,阐述了选择Glide的原因,并提供了详细的使用示例,包括简单的图片加载、图片列表加载及配置说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Glide是一个Android图片加载库,由Goodle维护

相关文档

官方文档: https://github.com/bumptech/glide
这里写图片描述

Gradle

repositories {
  mavenCentral() // jcenter() works as well because it pulls from Maven Central
}

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

一个极好的Glide教程翻译系列:http://mrfu.me/2016/02/27/Glide_Getting_Started/

为什么选择Glide

当前较为知名的几个图片加载库是Universal-Image_loader、Glide、Fresco、Picasso。
经过比较查询资料,得出以下结论 :

UIL的库2015年年底作者已经停止维护,so,如果是新开始的项目建议不要使用了
Gilde是Picasso的优化版,没有对比就没有伤害。so,Picasson pass。
最后就是Facebook的Fresco,听说极为强大和高效率,但是大小有4M。
最后Glide,google维护。Picasson的优化版,使用简单,也许没有Fresco那么强大,但是觉得完全可以hold住大部分项目。

综上所述,最终决定选择Glide作为项目开发图片加载库。使用的时候再自己封装一层util层,如果之后开发需要替换也较为方便。

如何使用

// 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/gEgYUd").into(imageView);
}

// For a simple image 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;
}

Glide 建造者要求最少有三个参数。

with(Context context) - 对于很多 Android API 调用,Context 是必须的。Glide 在这里也一样
load(String imageUrl) - 这里你可以指定哪个图片应该被加载,同上它会是一个字符串的形式表示一个网络图片的 URL
into(ImageView targetImageView) 你的图片会显示到对应的 ImageView 中。

混淆处理

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

除此之外;Glide还可以加载Gif,video。同时含有很多其他功能。详细可以在之前文档中查询。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值