问题
I have faced with an issue with data binding for different layouts. I have layout file for different orientation. For portrait mode:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
and for landspace mode:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/extra_container"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
And when I use it for binding via
ViewBinding binding = DataBindingUtil.setContentView(this, R.layout.view);
I have no access for extraContainer
from current binding.
Possible solution to add the view with same id and check the view class in runtime. Any other solutions ?
回答1:
I don't have solution for DataBinding
with different configuration. But I have suggestion like, remove that "tablet" layout from res/layout-sw600dp-land/view.xml
and merge it with default view.
Check with orientation and initialize extra_container
layout in landscape mode else hide it and don't initialize.
回答2:
Issue was fixed by updating Gradle version to 2.1.0, but there are no mentions on Gradle Revision and I dont know how it was related to Gradle version.
来源:https://stackoverflow.com/questions/36862494/data-binding-for-alternative-layouts