菜鸟请教一个基础问题

#58 · closed · 1 comments

View on GitHub ↗

zkzk7749

菜鸟请教一个基础问题啊,咱们这个库支持无缝切换 DataBinding,有没有demo啊

Comments

DylanCaiCoding

直接使用 DataBinding 就可以,如果 ViewBinding 和 DataBinding 都开启了,那么布局上用 `<layout/>` 标签包裹就是用了 DataBinding,否则是用 ViewBinding。其它的东西不需要改。 ```xml <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="vm" type="com.dylanc.dontforget.ui.login.LoginViewModel" /> </data> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> </androidx.constraintlayout.widget.ConstraintLayout> </layout> ``` ```kotlin binding.vm = viewModel ``` 也就说想用 DataBinding 就在 build.gradle 开启后,给对应的布局包裹 `<layout/>` 标签即可,其它的用法不用改。