- bind
<include layout="@layout/include_demo" app:employee="@{employee}"/>
include_demo.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="employee"
type="com.mooc.databingdingtest.Employee" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!--监听器绑定的语法——表达式语法-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{employee.firstName}"
android:textSize="24sp"
android:gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{employee.lastName}"
android:textSize="24sp"
android:gravity="center" />
</LinearLayout>
</layout>
- 尚不支持direct child,如root为merge
ViewStub
- ViewStub proxy final field
- ViewStubProxy
- OnInflateListener
viewstub.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"/>
</LinearLayout>
activity_demo.xml
<ViewStub
android:id="@+id/view_stub"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/viewstub"/>
DemoActivity.java 只有在调用了才显示
binding.viewStub.getViewStub().inflate();
网友评论