【发布时间】:2016-07-23 19:41:03
【问题描述】:
我有两种布局:一种用于 v19+,另一种用于早期版本。它们包含具有不同 ID 的不同视图。我怎么能说我想同时使用这两种布局的 Android DataBinding 框架?它只为一种布局生成视图(随机选择)。
布局/temp_view.xml:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="block"
type="ru.temp.model.content.blocks.WebMediaBlock" />
<import type="ru.temp.model.Types.ProviderTypes" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:background="@android:color/white">
<ImageView
android:id="@+id/provider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="@dimen/size5"
android:src="@{ProviderTypes.fromString(block.provider).getResId()}" />
</FrameLayout>
</layout>
layout-v19/temp_view.xml:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="block"
type="ru.temp.model.content.blocks.WebMediaBlock" />
<import type="ru.temp.model.Types.ProviderTypes" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:background="@android:color/white">
<ru.temp.utils.EmbedView
android:id="@+id/media_embed"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ru.temp.structure.static_material.CreditsView
android:id="@+id/credits_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</layout>
更新:
我终于找到了问题的根源。我不知道为什么,但是在使用 minSdkVersion 21 时它不会生成 *BindingImpl 文件。如果指定早期版本,它就像@yigit 所说的那样工作
【问题讨论】:
-
您也可以查看this教程供您参考。
-
不涵盖问题详情
标签: android data-binding android-databinding