Android 图片加载和缓存库,Glide 3.5.0 发布

jopen 9年前

Glide是一个囊括了图片下载、剪裁、内存和磁盘缓存,以及位图重用功能于一体的快速高效图像加载库,同时也方便了接口的使用。默认情况下,Glide库在Google Vooley项目的基础上实现了通过http协议的图像获取以及Android并行网络的操作。

项目主页:http://www.open-open.com/lib/view/home/1395149765290

Glide 3.5.0 发布,此版本是增量版本,包括一些新特性和重要的 bug 修复。

新特性

  • 添加 GlideModules,更简单的延迟配置 (#311).

  • 支持原始大小 (#274):

// You can override a view's size to request the original image:Glide.with(context)      .load(myUrl)      .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)      .into(myImageVIew);// SimpleTarget also now defaults to SIZE_ORIGINAL:Glide.with(context)      .load(myUrl)      .into(new SimpleTarget<Bitmap>() {        @Override          public void onResourceReady(Bitmap bitmap, GlideAnimation animation) {            ...          }      });
  • 改进 ListPrerloader API, including an interface allowing different sizes per position thanks to @DavidWiesner (#273)

  • [ALPHA] AppWidget 和 NotificationTarget实现 thanks to @pavlospt (#242):

AppWidgetTarget widgetTarget =           new AppWidgetTarget(context, remoteViews, R.id.view_id, 300, 400, R.id.widget_id);Glide.with(context)      .asBitmap()      .load(myUrl)      .into(widgetTarget);
  • Override values are passed through to thumbnails (#236).

  • Automatically call trim/clear memory based on ComponentCallbacks (9063f6c).

Build/Infrastructure

  • 更新到 Robolectric 2.4 thanks to @TWiStErRob (#249).

  • 更新到 Android gradle plugin 1.0+ (ba32d32).

  • 添加 Intellij 文件,开发更方便 (e34df44)

Bugs 修复

性能

  • Fixed needlessly copying Bitmaps decoded from data without an EXIF orientation tag (#270).

  • Freed thumbnails eagerly when full loads finish (#237).

  • Fixed a strict mode violation initializing the disk cache on Lollipop (#298).

  • Fixed a NetworkOnMainThread exception in the OkHttp integration library (#257)

  • Calculate sample size correctly thanks to @jisung (#288)

Rendering

  • Worked around a framework issue in KitKat and Lollipop causing certain types of Bitmaps to render old data (#301).

  • Fixed large BMPs failing to render (#283).

  • Fixed decode failure for images with minimal EXIF segments (#286).

  • Fixed a bug causing shared color filters (#276).

其他

  • Fixed a crash when the Glide singleton is instantiated on a background thread (#295).

  • Fixed a crash when completing loads started or cancelled other loads (#303).

  • Fixed skipMemoryCache not always skipping the memory cache (#258).

示例代码:

// 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;  }