替代布局的数据绑定

Data Binding for alternative layouts

我遇到了不同布局的数据绑定问题。 我有不同方向的布局文件。 对于纵向模式:

<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>

对于陆地模式:

<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>

当我使用它进行绑定时

ViewBinding binding = DataBindingUtil.setContentView(this, R.layout.view);

我无法从当前绑定访问 extraContainer

添加具有相同 ID 的视图并在运行时检查视图 class 的可能解决方案。还有其他解决方案吗?

我没有 DataBinding 不同配置的解决方案。但我有这样的建议,从 res/layout-sw600dp-land/view.xml 中删除 "tablet" 布局并将其与默认视图合并。

检查方向并在横向模式下初始化 extra_container 布局,否则隐藏它并且不初始化。

问题已通过将 Gradle 版本更新到 2.1.0 得到解决,但是 Gradle 修订版中没有提及,我不知道它与 Gradle 版本有什么关系。