1.AS中引用
这里针对as2.3而言
在app module 的build.gradle中开启databinding
android {
....
dataBinding {
enabled = true
}
}
//2.3之后需加入此句才能够正常使用
dependencies {
annotationProcessor 'com.android.databinding:compiler:2.3.0'
}
2.基本使用
每次修改完后,须使用make moudle或者make project对模块或者项目进行编译
Binding Data
@Override
protected void onCreate(Bundle savedInstanceState) {
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.setContent("hello dataBinding");
}
Data Binding Layout Files
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="content"
type="String">
</variable>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textIsSelectable="true"
android:text="@{content}" />
</LinearLayout>
</layout>
未完待续…