0

当我尝试在我的 BindingAdapter 中放置第二个参数“imgError”时出现错误。

这是我的 BindingAdapter :

@BindingAdapter("imageUrl", "imgError", requireAll = true)
fun loadImage(view: ImageView, imageUrl: String?, imgError: Drawable) {
    if (!imageUrl.isNullOrEmpty())
        Picasso.get().load(imageUrl).error(imgError).into(view)
    else
        view.setImageDrawable(imgError)
}

我有这个错误:

AAPT: error: attribute imgError not found

我尝试了不同的方法来解决它,但没有任何效果。

这是我如何使用它:

<com.google.android.material.imageview.ShapeableImageView
                android:id="@+id/shapeableImageView"
                android:layout_width="75dp"
                android:layout_height="75dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:shapeAppearanceOverlay="@style/ShapeCorner"
                app:imageUrl="@{profile.photo.url}"
                app:imgError="@drawable/ic_placeholder_user_photo"
                tools:srcCompat="@drawable/ic_placeholder_user_photo"/>
4

1 回答 1

0

我的错误是在不使用数据绑定的情况下设置我的可绘制对象:

app:imgError="@{@drawable/ic_placeholder_user_photo}"
于 2021-02-21T17:22:00.857 回答