Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t通过数据绑定(@BindingAdapter)加载映像:AAPT:error:attribute_Android_Android Databinding - Fatal编程技术网

Android Can';t通过数据绑定(@BindingAdapter)加载映像:AAPT:error:attribute

Android Can';t通过数据绑定(@BindingAdapter)加载映像:AAPT:error:attribute,android,android-databinding,Android,Android Databinding,安卓工作室3.6 build.gradle: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { viewBinding { enabled = true } dataBinding { enabled = true } compi

安卓工作室3.6

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    viewBinding {
        enabled = true
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
在某些类中,例如MyAdapter,我创建了带有注释的公共静态方法
loadImage

public class MyAdapter extends DataBindingRecyclerViewAdapter {

    public MyAdapter(Context context, List<?> data) {
        super(context, data);
    }

    @Override
    protected int getLayoutForPosition(int position) {
        return R.layout.forecast_data_list_item;
    }

    @BindingAdapter({"app:weatherImage"})
    public static void loadImage(ImageView view, String imageUrl) {
        Glide.with(view.getContext())
                .load(imageUrl).apply(new RequestOptions().circleCrop())
                .into(view);
    }

}

在BindingAdapter中

 @BindingAdapter("app:weatherImage")
    @JvmStatic
    fun setSelectedBackGround(view: ImageView, imageUrl: String) {
        Glide.with(view.getContext())
            .load(imageUrl).apply(new RequestOptions().circleCrop())
            .into(view);
    }
在XMl中,可以这样使用它

<ImageView
            android:id="@+id/imageView"
            android:layout_width="96dp"
            android:layout_height="96dp"
            android:layout_margin="@dimen/half_default_margin"
            android:scaleType="centerCrop"
            android:src="@drawable/default_image"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/containerRight"
            app:layout_constraintStart_toStartOf="parent"
            app:weatherImage="@{`http://www.gravatar.com/avatar/11111?s=200x200`}"
            app:layout_constraintTop_toTopOf="parent" />

您需要将此行更改为

  app:weatherImage="http://www.gravatar.com/avatar/11111?s=200x200"
  app:weatherImage='@{@string/image_url_link}'
差不多

  app:weatherImage="http://www.gravatar.com/avatar/11111?s=200x200"
  app:weatherImage='@{@string/image_url_link}'

能否尝试从绑定适配器方法中删除app:。因此,您只需执行这个
@BindingAdapter({“app:weatherImage”})
即可
@BindingAdapter({“weatherImage”})
app:weatherImage=“@{}”