我想使用 Glide Android 库下载图像并显示在ImageView
.
在之前的版本中我们使用:
Glide.with(mContext).load(imgUrl)
.thumbnail(0.5f)
.placeholder(R.drawable.PLACEHOLDER_IMAGE_NAME)
.error(R.drawable.ERROR_IMAGE_NAME)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
但我看过Glide的文档:
它说使用GlideApp.with()
反而Glide.with()
我担心的是缺少占位符、错误、GlideApp 和其他选项。
我在用
compile 'com.github.bumptech.glide:glide:4.0.0'
我哪里做错了?参考here http://bumptech.github.io/glide/doc/getting-started.html.
How has GlideApp.with()
被使用过?
API 与以下内容在同一个包中生成AppGlideModule
并被命名为GlideApp
默认情况下。应用程序可以通过启动所有负载来使用 APIGlideApp.with()
代替Glide.with()
:
GlideApp.with(fragment)
.load(myUrl)
.placeholder(placeholder)
.fitCenter()
.into(imageView);
尝试使用请求选项 http://bumptech.github.io/glide/doc/migrating.html#requestoptions:
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.ic_placeholder);
requestOptions.error(R.drawable.ic_error);
Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.load(url).into(holder.imageView);
EDIT
If .setDefaultRequestOptions(requestOptions)
不起作用,使用.apply(requestOptions)
:
Glide.with(MainActivity.this)
.load(url)
.apply(requestOptions)
.into(imageview);
// or this
Glide.with(MainActivity.this)
.load(url)
.apply(new RequestOptions().placeholder(R.drawable.booked_circle).error(R.drawable.booked_circle))
.into(imageview);
// or this
Glide.with(MainActivity.this)
.load(url)
.apply(RequestOptions.placeholderOf(R.drawable.booked_circle).error(R.drawable.))
.into(imageview);
编辑 2 奖金
以下是 Glide-4 中的一些其他变化
- 如何使用requestOptions.circleCropTransform(); https://stackoverflow.com/questions/49399459/glid4-bitmapimageviewtarget-at-into-method/49399683#49399683
- 如何使用Cross fades() https://stackoverflow.com/questions/50174277/glide-withcontext-loadfile-bitmaplist-getposition-showing-error/50174551#50174551
- 如何使用GlideDrawableImageViewTarget https://stackoverflow.com/questions/51531229/glidedrawableimageviewtarget-not-found-in-glide-4/51531284#51531284在 Glide-4 中
- 如何使用GifDrawable https://stackoverflow.com/questions/52291674/glide-does-not-accepting-gifdrawable-as-target-parameter/52291959#52291959作为目标参数
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)