Android - 无法识别 Glide“.placeholder”方法

Android - Glide ".placeholder" method not recognized

我有回收站观点。在适配器的 onBindViewHolder 方法中,我有以下代码来加载图像:

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        Log.i("TEST-APP", "Binding View Holder")

        Glide.with(context)
                .load(items[position])
                .placeholder(R.drawable.animated_loading_icon)
                .into(holder.imageView)
    }

但是,Android Studio 表示 "placeholder" 是一个未解决的参考。这令人困惑,因为 documentation 表明这是加载占位符的正确方法。

我做错了什么?

此外,这是我在 RecyclerViewAdapter class

中的导入
package com.example.myname.recylerviewtest

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.*
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.recyclerview_item_column.view.*

最后,这是我在 build.gradle 中的依赖项:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
api 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

如Glide所示documentation:

Most options in Glide can be applied using the RequestOptions class and the apply() method.

Use request options to apply (among others):

Placeholders
Transformations
Caching Strategies
Component specific options, like encode quality, or decode Bitmap configurations.

所以,如果你想使用占位符,你有两个选择。

其中一种是这样做的:

Glide.with(context)
    .load(items[position])
    .apply(RequestOptions()
        .placeholder(R.drawable.animated_loading_icon)
    )
    .into(holder.imageView)

另一个选择是实施 Generated API