Google推荐的图片加载库Glide介绍(与Picasso比较)一
来源:互联网 发布:ubuntu 12.04 双系统 编辑:程序博客网 时间:2024/06/04 19:22
在泰国举行的谷歌开发者论坛上,谷歌为我们介绍了一个名叫 Glide 的图片加载库,作者是bumptech。这个库被广泛的运用在google的开源项目中,包括2014年google I/O大会上发布的官方app。
它的成功让我非常感兴趣。我花了一整晚的时间把玩,决定分享一些自己的经验。在开始之前我想说,Glide和Picasso有90%的相似度,准确的说,就是Picasso的克隆版本。但是在细节上还是有不少区别的。
导入库
Picasso和Glide都在jcenter上。在项目中添加依赖非常简单:
Picasso
ortant; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background: none !important;" >ortant; border: 0px !important; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: inherit !important; background: none !important;" >ortant; margin: 0px !important; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: rgb(175, 175, 175) !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >ortant; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >dependencies {de> de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" > de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >compile de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: blue !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >'com.squareup.picasso:picasso:2.5.1'de> de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >}de>
1
2
3
ortant; margin: 0px !impGlide
ortant; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background: none !important;" >ortant; border: 0px !important; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: inherit !important; background: none !important;" >ortant; margin: 0px !important; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: rgb(175, 175, 175) !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >ortant; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >dependencies {de> de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" > de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >compile de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: blue !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >'com.github.bumptech.glide:glide:3.5.2'de> de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" > de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >compile de>de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: blue !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >'com.android.support:support-v4:22.0.0'de> de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: black !important; background-image: none !important; background-attachment: initial !important; background-color: rgba(0, 0, 0, 0.0392157); background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background- !important; background-repeat: initial !important;" >}de>
1
2
3
4
ortant; margin: 0px !impGlide需要依赖Support Library v4,别忘了。其实Support Library v4已经是应用程序的标配了,这不是什么问题。
基础
就如我所说的Glide和Picasso非常相似,Glide加载图片的方法和Picasso如出一辙。
Picasso
ortant; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background: none !important;" >ortant; border: 0px !important; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: inherit !important; background: none !important;" >ortant; margin: 0px !important; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !important; color: rgb(175, 175, 175) !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >ortant; font-size: 1em !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; right: auto !important; top: auto !important; vertical-align: baseline !important; min-height: inherit !important; background-image: none !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-repeat: initial !important;" >de style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0px; padding: 0.2em 0px; border-radius: 3px; line-height: normal; font-stretch: normal; box-sizing: content-box !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important;; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: inherit !imp
1
2
3
ortant; margin: 0px !imp