I need to specify a same placeholder for all image view, it seem like i can only set placeholder for every request.
Glide.with(mContext).load(mUrl).placeholder(R.drawable.placeholder).into(mImageView);
Does Glide support configure a global placeholder for all image request in application?
Thanks!
I'm not aware of this is possible currently, it may be possible in the future (4.0), @sjudd can confirm this.
I usually create a set of static methods which preset generic stuff "globally", something like:
class Pic {
static DrawableRequestBuilder<String> url(Context context) {
return Glide.with(context)
.fromString()
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.animate(R.anim.my_fancy_anim)
;
}
...
}
// and then
Pic.url(mContext).load("...").into(mImageView);
This reduces clutter at image loading, makes it easy to change all loads at once, and gives the flexibility of creating minor variants (it's likely you'll want some places to have a different placeholder).
I used OkHttp to integrate with Glide, after i upgraded OkHttp to latest version(compile 'com.squareup.okhttp:okhttp:2.4.0'
) it fixed. It seem to OkHttp cloud encode the url nicely.
Anyway, the method Pic.url(mContext).load("...").into(mImageView); is awesome,i will try it. Thank you.:)
Yes this should be possible in 4.0 You can specify a set of global options to apply to all requests, which includes the standard placeholder.
@TWiStErRob's work around here is what I've done as well for 3.x
This came up as the only result so I'll add to this the 4.0 way of solving the issue.
object GlideFactory {
private val defaultOptions = RequestOptions().placeholder(R.drawable.placeholder)
fun with(context: Context) = GlideApp.with(context).applyDefaultRequestOptions(defaultOptions)
fun with(activity: Activity) = GlideApp.with(activity).applyDefaultRequestOptions(defaultOptions)
fun with(activity: FragmentActivity) = GlideApp.with(activity).applyDefaultRequestOptions(defaultOptions)
fun with(fragment: Fragment) = GlideApp.with(fragment).applyDefaultRequestOptions(defaultOptions)
fun with(view: View) = GlideApp.with(view).applyDefaultRequestOptions(defaultOptions)
}
@aromano272 you can set default request options globally in a GlideModule: http://bumptech.github.io/glide/doc/configuration.html#default-request-options
@aromano272 you can set default request options globally in a GlideModule: http://bumptech.github.io/glide/doc/configuration.html#default-request-options
Ohh ok didn't know that, even better than thanks!
Most helpful comment
I'm not aware of this is possible currently, it may be possible in the future (4.0), @sjudd can confirm this.
I usually create a set of static methods which preset generic stuff "globally", something like:
This reduces clutter at image loading, makes it easy to change all loads at once, and gives the flexibility of creating minor variants (it's likely you'll want some places to have a different placeholder).