Android Custom View使用Databinding


Android Custom View是可以使用 databinding 的

            //java.lang.IllegalArgumentException: View is not a binding layout
// val bindingTemp = DataBindingUtil.bind<V>(view)
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
// val bindingTemp = DataBindingUtil.inflate<MyviewTestBinding>(inflater,getCustomLayoutResId(),this,true)

使用Databinding会导致预览图出不来,但可以正常使用
Exception Details java.lang.ClassNotFoundException: androidx.databinding.DataBinderMapperImpl   
at java.lang.ClassLoader.loadClass(ClassLoader.java:589)   
at java.lang.ClassLoader.loadClass(ClassLoader.java:522)   
at com.robertsi.myview.ui.DemoTwoTextView.getViewBinding   ... (DemoTwoTextView.kt:24)

使用 buildFeatures {
    dataBinding true
}
Activity和Fragment的 layout 可以生成 xml对象文件
但 Custom view的 layout 不会生成
 

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/java/275583.html

(0)
上一篇 2022年7月20日 11:35
下一篇 2022年7月20日 12:33

相关推荐

发表回复

登录后才能评论