主布局文件
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/tools">
<data>
<import type="com.farmtruth.brand.vm.BrandViewModel" />
<variable
name="vm"
type="BrandViewModel"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/brand_include_data"
bind:vm="@{vm}"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</layout>
include的布局文件
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.farmtruth.brand.vm.BrandViewModel" />
<variable
name="vm"
type="BrandViewModel" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_149"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20">
<TextView
style="@style/brand_style_brand_function_group_name"
android:text="@string/brand_manage_brand_team_customer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_77"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingBottom="@dimen/dp_18"
android:weightSum="4">
<TextView
style="@style/brand_style_brand_function_group_item_name"
android:drawableTop="@drawable/brand_icon_main_brand_info"
android:onClick="@{()->vm.comeToBrandMainPage()}"
android:text="@string/brand_main_brand" />
<TextView
android:id="@+id/tv_brand_team"
style="@style/brand_style_brand_function_group_item_name"
android:drawableTop="@drawable/brand_icon_main_team"
android:onClick="@{()->vm.comeToTeamPage()}"
android:text="@string/brand_team_team" />
<TextView
style="@style/brand_style_brand_function_group_item_name"
android:drawableTop="@drawable/brand_icon_main_customer"
android:onClick="@{()->vm.comeToCustomerPage()}"
android:text="@string/brand_customer" />
<TextView
style="@style/brand_style_brand_function_group_item_name"
android:drawableTop="@drawable/brand_icon_main_contact"
android:onClick="@{()->vm.comeToContactsPage()}"
android:text="@string/brand_contacts" />
</LinearLayout>
</RelativeLayout>
</layout>
主布局里的bind:vm="@{vm}"就是传递数据到include布局文件中,在解析布局文件的时候就可以使用主布局生成的对应的ActivityMainBinding中设置的数据了.
网友评论