0
上下文
Android中的XML佈局會變得複雜。因此,將它們分解成概念獨立的模塊是一種很好的做法。請看下面的例子:使用相同的數據綁定上下文分解複雜的XML佈局
主要佈局:
<layout>
<data>
<variable name="someVar" type="some.custom.Type"/>
</data>
<SomeLayout
...
android:someAttribute="@{someVar.someProperty}" />
<include layout="@layout/some_other_layout />
</layout>
和some_other_layout.xml
:
<SomeOtherLayout
...
android:someOtherAttribute="@{someVar.someOtherProperty}" />
問題
是否有可能使用相同的數據綁定上下文(無論是內部<data>
)在兩個分開的佈局(如在給出的例子中)?
這樣做會天真地導致java.lang.IllegalStateException
。