databinding

237 阅读1分钟
  1. step 1
    dataBinding {
        enabled = true
    }
  1. step 2
<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>
    </data>
    <!-- layouts...-->
</layout>
  1. step3
//ViewDataBinding 应为 布局id+Binding
LayoutIdBinding inflate = DataBindingUtil.inflate(LayoutInflate, LayoutId,null,false);
  1. step4
setContentView(inflate.getRoot());