我有一个回收者的观点。在适配器的 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 说“占位符”是一个 Unresolved 引用。这令人困惑,因为 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
关于kotlin - Android - Glide ".placeholder"方法无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50393663/