【问题标题】:Glide does not resolve its methodGlide 没有解决它的方法
【发布时间】:2017-05-26 10:07:03
【问题描述】:

今天我尝试在我的 android 应用程序中使用Glide 图像加载器,同时使用这个我遇到了无法解决问题的方法。

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .into(mUserImage);

这段代码工作得很好。但是当我尝试这个时

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .placeholder(R.mipmap.ic_launcher)
     .fitCenter()
     .into(mUserImage);

那么这句话不能解决方法fitCenter()placeholder。 我错过了什么?

【问题讨论】:

  • 您使用的是哪个滑翔版本?

标签: android android-glide


【解决方案1】:

似乎更新的库有任何问题。添加 .apply(new RequestOptions() 以继续使用最新版本。

代码

Glide
 .with(this)
 .load(R.drawable.image_default_profile_picture)
 .apply(new RequestOptions()
 .placeholder(R.mipmap.ic_launcher)
 .fitCenter())
 .into(mUserImage);

【讨论】:

  • 这对我有用,谢谢!附带说明,您可以将“annotationProcessor”保持原样(4.0.0-RC0)。
  • 我已经这样做了。但无法解决问题。ver 3.5.2 不会让我使用 asGIf() 方法。
  • 这不是降级版本的解决方案,请参考@James Jordan Taylor的回答。
  • Sameer Bhat 尝试使用以下评论编辑帖子:“您错过了一个右圆括号,谢谢顺便说一句”我不确定他们是否提出了正确的更改,但请检查您的语法
  • Glide.with(context*).using(FirebaseImageLoader()).load(storageReference).into(holder.image)using 方法未找到。你能帮忙吗?
【解决方案2】:

你仍然可以在最新版本的 Glide 中使用.placeholder(),你只需要将它作为应用的RequestOption 添加到方法链中,即

Glide.with(this)
     .load(floorplanUrl)
     .apply(new RequestOptions()
           .placeholder(R.drawable.floorplan_unavailable))
     .into(floorplanImageView);

【讨论】:

  • 这应该是被接受的答案,而不是给出降级滑翔版本的答案。
  • 谢谢,这很有帮助!我刚刚升级了旧代码,一些引用引发了错误。我发现现在使用 Default Glide 而不是 Customizable Fluid Interface 时需要这样做,在这种情况下我们需要引用 GlideApp。我得到了 Peitek 和 Pohls 在 Android 上的可定制图像加载一书以获得更多解释和示例。
【解决方案3】:

如果你使用 Glide 包依赖 compile 'com.github.bumptech.glide:glide:3.7.0' 而不是使用下面的代码

Glide
    .with(your_context)
    .load(image_url)
    .centerCrop()
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imageView);

注意:doc 圆形图片:CircularImageView/CircularImageView/RoundedImageView 是 已知与 TransitionDrawable (.crossFade() 有问题 .thumbnail() 或 .placeholder()) 和动画 GIF,使用 BitmapTransformation(.circleCrop() 将在 v4 中可用)或 .dontAnimate() 来解决这个问题。

最新更新版本compile 'com.github.bumptech.glide:glide:4.1.1'或以上版本比使用以下代码

Glide.with(your_context)
     .load(url)
     .apply(new RequestOptions()
                .placeholder(R.mipmap.ic_loading_image)
                .centerCrop()
                .dontAnimate()
                .dontTransform())
                .into(imageView);

如果您想GIF File 加载到Glide,使用compile 'com.github.bumptech.glide:glide:3.7.0' 比在.load() 之后使用.asGif() 方法强>

Glide
    .with(your_context)
    .load(image_url)
    .asGif()
    .into(imageView);

如果您使用compile 'com.github.bumptech.glide:glide:4.1.1' 或更高(最新)的依赖项,

Glide
    .with(your_context)
    .asGif()
    .load(image_url)
    .into(imageView);

注意:如果您使用glide:glide:4.1.1或更高版本,则无需使用.asGif()方法加载GIF文件,它会 自动加载GIF File

查看最新版本的glide, Bug fixes, Features

【讨论】:

  • compile 'com.github.bumptech.glide:glide:4.1.1' 或更高版本对我有用。谢谢。
  • 你是 wc @IPKaal
【解决方案4】:

对于从 v4.0 开始的 Glide 版本使用 fitCenter() 和其他比例类型更改,您需要在您的应用中包含特殊类。

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
}

之后重建项目,你就可以开始使用 Glide 了

GlideApp.with(imageView)
    .load("...")
    .fitCenter()
    .into(imageView);

Documentation

【讨论】:

    【解决方案5】:

    滑翔版:4.8.0

    Glide.with(this)
            .load("https://media.giphy.com/media/98uBZTzlXMhkk/giphy.gif")
            .apply(new RequestOptions()
                    .placeholder(R.drawable.placeholder)
                    .error(R.drawable.error)
                    .centerCrop()
                    .fitCenter())
            .into(imageView);
    

    【讨论】:

      【解决方案6】:

      如果您仍想使用最新的库'com.github.bumptech.glide:glide:4.0.0-RC1'The official Github page 建议如下:

      圆形图片:CircularImageView/CircularImageView/RoundedImageView 是 已知与 TransitionDrawable (.crossFade() 有问题 .thumbnail() 或 .placeholder()) 和动画 GIF,使用 BitmapTransformation(.circleCrop() 将在 v4 中可用)或 .dontAnimate() 来解决问题。

      否则使用以下库版本:

      compile 'com.github.bumptech.glide:glide:3.7.0'
      

      【讨论】:

        【解决方案7】:

        编译这个库:-

        compile 'com.github.bumptech.glide:glide:3.7.0'
        

        【讨论】:

          猜你喜欢
          • 2018-07-03
          • 1970-01-01
          • 2021-05-07
          • 1970-01-01
          • 2018-07-17
          • 1970-01-01
          • 1970-01-01
          • 2020-09-16
          • 1970-01-01
          相关资源
          最近更新 更多