Glide

Android的图像加载和缓存库,专注于平滑滚动。(An image loading and caching library for Android focused on smooth scrolling)

Github stars Tracking Chart

Glide

查看Glide的文档 | 简体中文文档 | 向Glide报告问题

Glide是一个快速高效的Android开源媒体管理和图像加载框架,它将媒体解码,内存和磁盘缓存以及资源池包装成一个简单易用的界面。

Glide支持获取、解码和显示视频静止图像,图像和动画GIF。 Glide包含一个灵活的API允许开发人员插入几乎任何网络堆栈。默认情况下,Glide使用基于自定义的 HttpUrlConnection 而且还包括实用程序库,可以插入到Google的Volley项目或Square的OkHttp库中。

Glide的主要焦点是尽可能平滑和快速地滚动任何类型的图像列表,但Glide是几乎在任何情况下您都需要获取,调整大小和显示远程图像。

下载

有关详细说明和要求,请参阅Glide的下载和设置文档页面

您可以从GitHub的发布页下载一个jar包。

或者使用Gradle:

repositories {
  mavenCentral()
  google()
}

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.8.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

或Maven:

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>glide</artifactId>
  <version>4.8.0</version>
</dependency>
<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>compiler</artifactId>
  <version>4.8.0</version>
  <optional>true</optional>
</dependency>

有关使用最新优势的信息,请参阅快照文档页面。

ProGuard

根据您的ProGuard(DexGuard)配置和用法,您可能需要在proguard.cfg中包含以下行(请参阅下载和设置文档页面了解更多详情):

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

我如何使用Glide?

查看各种主题页面的文档,并参阅javadocs

对于Glide v3,请参阅 wiki

Glide的生成的API 的简单用例如下所示:

// For a simple view:
@Override public void onCreate(Bundle savedInstanceState) {
  ...
  ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  GlideApp.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);

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

  return myImageView;
}

状态

版本4现已发布并且稳定。更新目前至少每月发布一次,并提供新功能和错误修复。

评论/错误/问题/拉请求总是欢迎!有关如何报告问题,请阅读 CONTRIBUTING.md

兼容性

  • 最低Android SDK :Glide v4要求最低API级别为14。
  • 编译Android SDK :Glide v4要求您针对API 26或更高版本进行编译。

如果您需要支持较旧版本的Android,请考虑继续使用 Glide v3 ,该API适用于API 10 ,但没有积极维护。

  • OkHttp 3.x :有一个可选的依赖项,称为 okhttp3-integration ,参见文档页面
  • Volley :有一个可选的依赖项,称为 volley-integration ,请参阅文件页
  • Round Pictures : CircleImageView/CircularImageView/RoundedImageView 已知有issues 与 TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) 和动画GIF,请使用BitmapTransformation ( .circleCrop()将在v4)或 .dontAnimate()这个问题。
  • Huge Images(地图,连环漫画):Glide可以通过缩小图片来加载巨大图片,但不支持缩放和平移 ImageView ,因为它们需要特殊的资源优化(如平铺)在没有 OutOfMemoryError 的情况下工作

构建

使用Gradle构建Glide非常简单:

git clone https://github.com/bumptech/glide.git 
cd glide
./gradlew jar

注意:确保您的 Android SDK 安装了 Android支持库,并且您的 $ ANDROID_HOME 环境变量指向SDK或使用 sdk.dir = ... 行在根项目中添加 local.properties 文件。

示例

按照 Build 部分中的步骤设置项目,然后:

./gradlew :samples:flickr:run
./gradlew :samples:giphy:run
./gradlew :samples:svg:run
./gradlew :samples:contacturi:run

您也可以在发布页面上找到预编译的APK。

开发

按照 Build 部分中的步骤设置项目,然后根据需要编辑文件。 Android Studio 干净地导入Glide的源代码和测试,并且是推荐使用Glide的方式。

在Android Studio中打开项目:

  1. 转到文件菜单或欢迎屏幕
  2. 点击打开...
  3. 导航到Glide的根目录。
  4. 选择 setting.gradle

有关详情,请参阅贡献文档页

获得帮助

要报告特定的问题或功能请求,请在Github上开启新的问题。对于问题,建议或其他任何信息,请 Glide的讨论组或加入我们的IRC频道:irc.freenode.net#glide-library

贡献

在提交pull请求之前,贡献者必须签署Google的个人贡献者许可协议

感谢

作者

Sam Judd - 在GitHub上看@sjudd,在Twitter上看@samajudd

许可证

BSD,MIT和Apache 2.0的一部分。详细信息请参阅许可证文件。

声明

这不是Google的官方产品。

Main metrics

Overview
Name With Ownerbumptech/glide
Primary LanguageJava
Program languageJava (Language Count: 4)
PlatformAndroid
License:Other
所有者活动
Created At2013-07-08 22:52:33
Pushed At2025-06-05 22:35:01
Last Commit At2025-06-03 10:34:10
Release Count50
Last Release Namev5.0.0-rc01 (Posted on )
First Release Namev2.0-alpha (Posted on )
用户参与
Stargazers Count34.9k
Watchers Count1k
Fork Count6.2k
Commits Count3k
Has Issues Enabled
Issues Count4477
Issue Open Count558
Pull Requests Count557
Pull Requests Open Count34
Pull Requests Close Count406
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Glide

Maven Central Build Status, View Glide's documentation, 简体中文文档, Report an issue with Glide

Glide is a fast and efficient open source media management and image loading framework for Android that wraps media
decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API
that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based
stack, but also includes utility libraries plug in to Google's Volley project or Square's OkHttp library instead.

Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is
also effective for almost any case where you need to fetch, resize, and display a remote image.

Download

For detailed instructions and requirements, see Glide's download and setup docs page.

You can download a jar from GitHub's releases page.

Or use Gradle:

repositories {
  mavenCentral()
  google()
}

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.11.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}

Or Maven:

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>glide</artifactId>
  <version>4.11.0</version>
</dependency>
<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>compiler</artifactId>
  <version>4.11.0</version>
  <optional>true</optional>
</dependency>

For info on using the bleeding edge, see the Snapshots docs page.

ProGuard

Depending on your ProGuard (DexGuard) config and usage, you may need to include the following lines in your proguard.cfg (see the Download and Setup docs page for more details):

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

How do I use Glide?

Check out the documentation for pages on a variety of topics, and see the javadocs.

For Glide v3, see the wiki.

Simple use cases will look something like this:

// 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)
    .into(myImageView);

  return myImageView;
}

Status

Version 4 is now released and stable. Updates are released periodically with new features and bug fixes.

Comments/bugs/questions/pull requests are always welcome! Please read CONTRIBUTING.md on how to report issues.

Compatibility

  • Minimum Android SDK: Glide v4 requires a minimum API level of 14.
  • Compile Android SDK: Glide v4 requires you to compile against API 26 or later.

If you need to support older versions of Android, consider staying on Glide v3, which works on API 10, but is not actively maintained.

  • OkHttp 3.x: There is an optional dependency available called okhttp3-integration, see the docs page.
  • Volley: There is an optional dependency available called volley-integration, see the docs page.
  • Round Pictures: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.
  • Huge Images (maps, comic strips): Glide can load huge images by downsampling them, but does not support zooming and panning ImageViews as they require special resource optimizations (such as tiling) to work without OutOfMemoryErrors.

Build

Building Glide with gradle is fairly straight forward:

git clone https://github.com/bumptech/glide.git
cd glide
./gradlew jar

Note: Make sure your Android SDK has the Android Support Repository installed, and that your $ANDROID_HOME environment
variable is pointing at the SDK or add a local.properties file in the root project with a sdk.dir=... line.

Samples

Follow the steps in the Build section to set up the project and then:

./gradlew :samples:flickr:run
./gradlew :samples:giphy:run
./gradlew :samples:svg:run
./gradlew :samples:contacturi:run

You may also find precompiled APKs on the releases page.

Development

Follow the steps in the Build section to setup the project and then edit the files however you wish.
Android Studio cleanly imports both Glide's source and tests and is the recommended way to work with Glide.

To open the project in Android Studio:

  1. Go to File menu or the Welcome Screen
  2. Click on Open...
  3. Navigate to Glide's root directory.
  4. Select setting.gradle

For more details, see the Contributing docs page.

Getting Help

To report a specific problem or feature request, open a new issue on Github. For questions, suggestions, or
anything else, email Glide's discussion group, or join our IRC channel: irc.freenode.net#glide-library.

Contributing

Before submitting pull requests, contributors must sign Google's individual contributor license agreement.

Thanks

Author

Sam Judd - @sjudd on GitHub, @samajudd on Twitter

License

BSD, part MIT and Apache 2.0. See the LICENSE file for details.

Disclaimer

This is not an official Google product.