【问题标题】:Parameter not found using binding adapter使用绑定适配器找不到参数
【发布时间】:2021-02-18 09:30:20
【问题描述】:

当我尝试在 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"/>

【问题讨论】:

    标签: kotlin android-binding-adapter


    【解决方案1】:

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

    app:imgError="@{@drawable/ic_placeholder_user_photo}"
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多