Lac*_*dge 5 data-binding android android-databinding
我有2个布局:一个用于v19 +,另一个用于早期版本.它们包含具有不同ID的不同视图.我怎么能说我想要使用两种布局的Android DataBinding框架?它仅为一个布局生成视图(随机选择).
layout/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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
更新:
最后我发现了问题的根源.我不知道为什么但是在使用minSdkVersion 21时它不会生成*BindingImpl文件.如果指定早期版本它就像@yigit那样工作
数据绑定将生成一个基类,用作两者(变量)的公共接口。当您调用 ) 时,数据绑定将负责创建正确的实例DataBindingUtil.setContentView(activity, R.layout.tmp_view。
例如,在您的示例中,它将生成
TempViewBinding,TempViewBindingImpl和TempViewBindingV19Impl。<app module>/build/intermediates/classes/<your package>/databinding/编译后可以检查里面的这些类。
TempViewBinding是基类,它将具有每个布局的变量和视图的组合。如果您在 IDE 中没有看到它们,可能是 AS 中的自动完成错误(请提交错误)。
| 归档时间: |
|
| 查看次数: |
365 次 |
| 最近记录: |