Glide-4.0.0 缺少占位符、错误、GlideApp 并且没有解决它的方法占位符、错误 [英] Glide-4.0.0 Missing placeholder, error, GlideApp and does not resolve its method placeholder,error

查看:43
本文介绍了Glide-4.0.0 缺少占位符、错误、GlideApp 并且没有解决它的方法占位符、错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 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'

我哪里做错了?参考此处.

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);

推荐答案

尝试使用 RequestOptions:

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

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆