Android DataBinding Custom Binding Adapter Warning

后端 未结 3 816
感动是毒
感动是毒 2020-12-07 22:46

I followed the data binding documentation for Custom Binding Adapter for image loading from official Android Developers site: http://develo

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 23:17

    Actually there are still some tutorials which add prefix to the BindingAdapter annotation.

    Use @BindingAdapter({"imageUrl"}) without any prefix.

    
    

    Pro Tip

    You will not get warning when using android: prefix in BindingAdapter. Because that is encouraged. I will suggest to use @BindingAdapter("android:src") instead of creating a new attribute.

    @BindingAdapter("android:src")
    public static void setImageDrawable(ImageView view, Drawable drawable) {
        view.setImageDrawable(drawable);
    }
    

    and

    @BindingAdapter("android:src")
    public static void setImageFromUrl(ImageView view, String url) {
       // load image by glide, piccaso, that you use.
    }
    

    Create a new attribute only when you need it.

提交回复
热议问题