Data Binding for alternative layouts

爱⌒轻易说出口 提交于 2020-01-14 22:27:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!