问题描述
我遵循了来自Android开发人员官方网站的自定义绑定适配器的数据绑定文档,用于图像加载: http://developer.android.com/tools/data-binding/guide.html
I followed the data binding documentation for Custom Binding Adapter for image loading from official Android Developers site:http://developer.android.com/tools/data-binding/guide.html
成功编译代码后,我得到一条警告:
After successfully compiling the code I get a warning which is:
Warning:Application namespace for attribute bind:imageUrl will be ignored.
我的代码如下:
@BindingAdapter({"bind:imageUrl"})
public static void loadImage(final ImageView imageView, String url) {
imageView.setImageResource(R.drawable.ic_launcher);
AppController.getUniversalImageLoaderInstance().displayImage(url, imageView);
}
为什么会生成此警告?
还附有屏幕截图...
A screenshot is also attached...
推荐答案
我相信BindingAdapter
批注中确实忽略了名称空间.如果使用任何名称空间前缀,则无论是否与布局中使用的名称前缀匹配,都会发生该警告.如果您省略名称空间,就像这样:
I believe the namespace is truly ignored in the BindingAdapter
annotation. The warning occurs if you use any namespace prefix, regardless of whether it matches the one used in your layout or not. If you omit the namespace, like so:
@BindingAdapter({"imageUrl"})
...未发生警告.
我怀疑在将字符串用作注释实现中的键之前,已经存在警告我们的警告,以剥夺名称空间.当您认为布局可以自由声明其所需的任何名称空间时,这是有意义的,例如app:
或bind:
或foo:
,并且注释必须在所有这些情况下均有效.
I suspect the warning exists to alert us the namespace is stripped off before the string is used as a key in the annotation's implementation. Which makes sense when you consider layouts are free to declare whatever namespaces they want, e.g. app:
or bind:
or foo:
, and the annotation needs to work across all those cases.
这篇关于Android DataBinding自定义绑定适配器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!