【发布时间】:2019-02-12 05:43:03
【问题描述】:
我已经有一个绑定适配器来加载来自 URL 的 ImageView 中的图像。现在,我需要加载背景图像 URL 作为图像视图的背景,并且我正在使用数据绑定、滑动加载图像并将其写入 Kotlin。
如何为它编写一个绑定适配器?
这是我的 XML
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerInside"
app:backgroundImageUrl="@{item.backgroundImageUrl}"
app:mainImageUrl="@{item.mainImageUrl}"/>
【问题讨论】:
-
简单的只是制作以url和imageview为参数的方法并调用该方法。
-
这里Binding image using bindAdapter 是同样的例子,而不是毕加索使用滑翔为你的工作
-
@AbhayKoradiya 我已经有了将图像加载到图像视图的方法。如果我对背景图像执行相同操作,则不会显示背景图像
-
检查@PJain 的答案。
-
这是我用来将来自 url 的图像加载到图像视图的绑定适配器 @BindingAdapter("ImageUrl") fun loadImage(view: ImageView, imageUrl:String?) { Glide.with( view.context) .load(imageUrl) .into(view) }