databinding使用include

来源:互联网 发布:最终幻想模型制作软件 编辑:程序博客网 时间:2024/05/17 19:21

a.xml如下:

<?xml version="1.0" encoding="utf-8"?><layout>    <data>        <variable            name="bean"            type="com.Bean"/>    </data>    <LinearLayout        xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">        <include            layout="@layout/b"            app:bean="@{bean}"/>    </LinearLayout></layout>
include的文件b.xml如下:

<?xml version="1.0" encoding="utf-8"?><layout>    <data>        <variable            name="bean"            type="com.Bean"/>    </data>    <RelativeLayout        xmlns:android="http://schemas.android.com/apk/res/android"        android:layout_width="wrap_content"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="@{bean.state==1 ? @string/audit_ing : @string/audit_refuse}"/>    </RelativeLayout></layout>
注意使用方法是在引用的地方加了一句:

app:bean="@{bean}
相当于传值,把bean从a传到b。



参考:

DataBinding补坑