安卓 - Glide中的“.placeholder”方法无法识别

6

我有一个回收视图。在适配器的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”未解决的引用。这令人困惑,因为文档表明这是加载占位符的正确方式。

我做错了什么?

此外,在RecyclerViewAdapter类中,这是我的导入:

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'
}
1个回答

16

如Glide 文档所示:

Glide中的大多数选项都可以使用RequestOptions类和apply()方法应用。

使用请求选项来应用(其中包括):

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)

另一种选择是实现生成的API


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接