替代布局的数据绑定 [英] 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的视图并在运行时检查视图类.还有其他解决方案吗?
解决方案
已通过将Gradle版本更新为2.1.0修复了该问题,但是Gradle修订版没有提及,我不知道它与Gradle版本有何关系./p>
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 ?
解决方案
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.
这篇关于替代布局的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文