引用类
数据模型
public class Item {
    private String name;
    public String getName() {
        return name;
    }
}
布局 XML
你必须导入引用的类,就像在 Java 中一样。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
   <data>
       <import type="android.view.View"/>
       <variable name="item" type="com.example.Item"/>
   </data>
   <LinearLayout
       android:orientation="vertical"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       <!-- We reference the View class to set the visibility of this TextView -->
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@{item.name}"
           android:visibility="@{item.name == null ? View.VISIBLE : View.GONE"/>
   </LinearLayout>
</layout>
注意: 包 java.lang.*由系统自动导入。 (同时由 JVM 为 Java 制作)