我竟然找不到如何使用Glide这样简单的东西,可能是 的 Android上使用最多的图像库与Kotlin。 Glide的requestOptions文档显示了这个简单的代码。
val requestOptions = RequestOptions().error(R.drawable.error)
Glide.with(context)
.apply(requestOptions)
.load(myUrl)
.into(myView)
但似乎Kotlin的apply方法和Glide的apply方法有冲突。 我的requestOptions参数出现了 "Type Mismatch "错误。 请问有什么办法解决这个问题?还有为什么在Glides文档中没有明确标注?
你需要从glide中调用RequestBuilder的apply函数。只要改变顺序,然后调用 负载() 先是。
val requestOptions = RequestOptions().error(R.drawable.error)
Glide.with(context)
.load(myUrl)
.apply(requestOptions)
.into(myView)