因为Kotlin里没有static。所以你的DataBindingHelper长这样

object DataBindingHelper {
    @JvmStatic
    @BindingAdapter("imageurl")
    fun loadImage(imageView: ImageView, url: String) {
        Glide.with(imageView).load(url).placeholder(R.mipmap.ic_launcher)
            .error(R.mipmap.ic_launcher)
            .transition(DrawableTransitionOptions.withCrossFade())
            .centerCrop()
            .into(imageView)

    }
}

xml是这样的

            <ImageView
                android:id="@+id/img_"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toLeftOf="@+id/txt_content"
                android:src="@mipmap/ic_launcher"
                app:imageurl="@{url}"
                />

重点来了:这样写完后。程序还报错的话。那么来到你module下的build.gradle加上
apply plugin: ‘kotlin-kapt’ 就好了。

如对此有疑问,请联系qq1164688204。

推荐Android开源项目

项目功能介绍:RxJava2和Retrofit2项目,添加自动管理token功能,添加RxJava2生命周期管理,使用App架构设计是MVP模式和MVVM模式,同时使用组件化,部分代码使用Kotlin,此项目持续维护中。

项目地址:https://gitee.com/urasaki/RxJava2AndRetrofit2

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐