大佬教程收集整理的这篇文章主要介绍了Glide 生成大小为 0 的 ImageView,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 GlIDe 构建一个简单的 AndroID 应用程序。该功能很简单:应用程序发送网络请求并取回图像 URL 列表。然后使用 GlIDe 和 RecyclerVIEw,我想显示图像。
我希望显示图像的方式是它们应该填满屏幕的宽度,而高度应该自动调整以保持原始纵横比。
这是我的 RecyclerVIEw 的视图持有者的布局:
<androIDx.consTraintlayout.Widget.ConsTraintLayout
xmlns:app="http://scheR_407_11845@as.androID.com/apk/res-auto"
xmlns:androID="http://scheR_407_11845@as.androID.com/apk/res/androID"
androID:layout_wIDth="match_parent"
androID:layout_height="wrap_content">
<ImageVIEw
androID:ID="@+ID/image_vIEw"
androID:layout_wIDth="match_parent"
androID:layout_height="wrap_content"
app:layout_consTrainttop_totopOf="parent"
app:layout_consTraintStart_toStartOf="parent"
app:layout_consTraintEnd_toEndOf="parent"
androID:scaleType="center"
androID:layout_margintop="12dp"
androID:layout_marginStart="16dp"
androID:layout_marginEnd="16dp" />
</androIDx.consTraintlayout.Widget.ConsTraintLayout>
这是我的视图持有者的代码:
class PhotoVIEwHolder(private val binding: PhotoVIEwHolderBinding): RecyclerVIEw.VIEwHolder(binding.root) {
fun bind(imageUrl: String?) {
if (imageUrl != null) {
GlIDe.with(binding.imageVIEw).load(imageUrl).into(binding.imageVIEw)
}
}
}
然而,我在屏幕上看不到任何东西。使用布局检查器,我发现 ImageVIEws 在那里,它们只有 0 高和 0 宽:
我想知道为什么会这样。
我发现如果我把 Glide 代码改成这样:
Glide.with(binding.root.context)
.asBitmap()
.load(imageUrl)
.into(object: CustomTarget<Bitmap>() {
override fun onresourceReady(
resource: Bitmap,transition: Transition<in Bitmap>?
) {
binding.imageView.setImageBitmap(resourcE)
}
override fun onLoadCleared(placeholder: Drawable?) {}
})
然后就可以了。所以显然它必须使用CustomTarget
。我还是不明白为什么。
以上是大佬教程为你收集整理的Glide 生成大小为 0 的 ImageView全部内容,希望文章能够帮你解决Glide 生成大小为 0 的 ImageView所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。