Glide是目前 Android 上最流行的图片加载库之一。

目前Glide已经更新到了4.11.0

repositories {
  mavenCentral()
  google()
}

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

Glide V4和Glide V3 不同的使用方式。

Glide V4 版本

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.7.1'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
 RequestOptions requestOptions = new RequestOptions()
         .placeholder(R.drawable.defalut_image)
         .error(R.drawable.defalut_image)
         .priority(Priority.LOW)
         .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
 Glide.with(getActivity()).load(mImageUrl.
         replace("file://", ""))
         .apply(requestOptions)
         .listener(new RequestListener<Drawable>() {
             @Override
             public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {

                 return false;
             }

             @Override
             public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {

             }
         })
         .into(mPhotoView);

Glide V3 版本

dependencies {
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:19.1.0'
}
Glide.with(getActivity()).load(mImageUrl.replace("file://", ""))
		.error(R.drawable.defalut_image).priority(Priority.LOW)
		.diskCacheStrategy(DiskCacheStrategy.SOURCE)
		.listener(new RequestListener<String, GlideDrawable>() {
			@Override
			public boolean onException(Exception e, String s, Target<GlideDrawable> target, boolean b) {

				return false;
			}
			@Override
			public boolean onResourceReady(GlideDrawable glideDrawable, String s, Target<GlideDrawable> target, boolean b, boolean b1) {

				return false;
			}
		}).into(mPhotoView);

相关文章

暂无评论

none
暂无评论...