我正在尝试使用数据绑定加载图片,但一直没有成功。我的问题出在哪里?以下是我的代码和布局构造。
MyItemViewModel.kt
@BindingAdapter("imageUrl")
fun loadImage(view: RoundedImageView, url: String) = Glide.with(view.context).load(url).into(view)
布局文件.xml
<data>
<variable
name="viewModel"
type="com.myapp.app.ui.activity.albumlist.AlbumItemViewModel"/>
</data>
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="60dp"
android:id="@+id/ivRoundedAlbum"
android:layout_marginStart="@dimen/unit_20_dp"
app:riv_corner_radius="8dp"
app:imageUrl="@{viewModel.data.cover}"
android:layout_height="60dp"/>
@JvmStatic
标记。如果出现错误,可以将其移动到 companion object 中。 - Jeel Vankhede