替代布局的数据绑定

xUs*_*ser 6 android android-databinding

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

<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>
Run Code Online (Sandbox Code Playgroud)

对于陆地模式:

<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>
Run Code Online (Sandbox Code Playgroud)

当我使用它进行绑定时

ViewBinding binding = DataBindingUtil.setContentView(this, R.layout.view);
Run Code Online (Sandbox Code Playgroud)

我无法extraContainer从当前绑定访问。

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

xUs*_*ser 0

通过将 Gradle 版本更新到 2.1.0 解决了问题,但没有提及 Gradle 修订版,我不知道它与 Gradle 版本有何关系。