Glide-4.0.0缺少占位符,错误,GlideApp,并且无法解析其方法占位符,错误 [英] Glide-4.0.0 Missing placeholder, error, GlideApp and does not resolve its method placeholder,error
问题描述
我想使用Glide Android库下载图像并显示在ImageView
中.
I want to use the Glide Android library to download an image and show in ImageView
.
在以前的版本中,我们使用:
In the previous version we used:
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文档:
But I have seen Glide documentation:
它说使用
GlideApp.with()
代替Glide.with()
我担心的是缺少占位符,错误,GlideApp和其他选项.
My concern is a missing placeholder, error, GlideApp, and other options.
我正在使用
compile 'com.github.bumptech.glide:glide:4.0.0'
我在哪里做错了?参考此处.
Where am I doing wrong? With reference to here.
GlideApp.with()
的用法如何?
API在与AppGlideModule
相同的程序包中生成,默认情况下命名为GlideApp
.应用程序可以通过从GlideApp.with()
而不是Glide.with()
开始所有加载来使用API:
The API is generated in the same package as the AppGlideModule
and is named GlideApp
by default. Applications can use the API by starting all loads with GlideApp.with()
instead of Glide.with()
:
GlideApp.with(fragment)
.load(myUrl)
.placeholder(placeholder)
.fitCenter()
.into(imageView);
推荐答案
Try using 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);
编辑
如果.setDefaultRequestOptions(requestOptions)
不起作用,请使用.apply(requestOptions)
:
If .setDefaultRequestOptions(requestOptions)
does not work, use .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的其他一些更改
Here are some other changes in Glide-4
- 如何使用
requestOptions.circleCropTransform();
- 如何使用
Cross fades()
- 如何使用
GlideDrawableImageViewTarget
在Glide-4中 - 如何使用
GifDrawable
作为目标参数
- How to use
requestOptions.circleCropTransform();
- How to use
Cross fades()
- How to use
GlideDrawableImageViewTarget
in Glide-4 - How to use
GifDrawable
as target parameter
这篇关于Glide-4.0.0缺少占位符,错误,GlideApp,并且无法解析其方法占位符,错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!