Android Kotlin - 在 ImageView 内加载图像
Android Kotlin - On image inside ImageView loaded
这是我试过的
Glide
.with(context)
.load(imgUrl)
.listener(object : RequestListener<Drawable>{
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return false
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
return false
}
})
.into(holder.image)
object
上的第一个错误:
对象不是抽象的,不实现抽象成员public abstract fun onResourceReady(resource: Drawable!, model: Any!, target: Target!, dataSource: DataSource!, isFirstResource: Boolean): Boolean在 com.bumptech.glide.request.RequestListener
中定义
Drawable
上的第二个错误:
注释不需要类型参数 class 目标
第二次出现第三次错误 override
:
'onResourceReady' 什么都不覆盖
这里有什么问题?或者还有其他解决办法吗??
出现这些错误是因为您导入了错误版本的 Target class。您应该从 com.bumptech.glide.request.target.Target 包中导入 "Target"。
import android.graphics.drawable.Drawable
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
}
这是我试过的
Glide
.with(context)
.load(imgUrl)
.listener(object : RequestListener<Drawable>{
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return false
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
return false
}
})
.into(holder.image)
object
上的第一个错误:
对象不是抽象的,不实现抽象成员public abstract fun onResourceReady(resource: Drawable!, model: Any!, target: Target!, dataSource: DataSource!, isFirstResource: Boolean): Boolean在 com.bumptech.glide.request.RequestListener
中定义Drawable
上的第二个错误:
注释不需要类型参数 class 目标
第二次出现第三次错误 override
:
'onResourceReady' 什么都不覆盖
这里有什么问题?或者还有其他解决办法吗??
出现这些错误是因为您导入了错误版本的 Target class。您应该从 com.bumptech.glide.request.target.Target 包中导入 "Target"。
import android.graphics.drawable.Drawable
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
}