Android:配置 .xml 必须与根元素的 ID 一致

T D*_*yen 8 xml android android-layout

我的应用程序曾经编译成功,但编译时突然产生错误消息:

Execution failed for task ':app:dataBindingGenBaseClassesDebug'.
> Configurations for item_list.xml must agree on the root element's ID.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Run Code Online (Sandbox Code Playgroud)

我有 item_list 和 item_list(landscape) 的两个布局,并且没有修改任何这些文件。我用的是安卓4.2。

Mar*_*ler 14

如果您有两个布局,则您已经更改了它们,因为您没有使用框架的默认布局。该错误消息意味着同一布局的这两个版本在其根节点上有两个不同的 ID。要解决此问题,只需在两个根节点上使用相同的 ID 即可。

  • 好的,但是如果我有一个 `<include>` (如在主/详细流程中)并且在一个 xml 文件中我只有一个 RecyclerView 而在另一个(对于 900dp 屏幕宽)我在 LinearLayout 中有 RecyclerView 该怎么办?两个RecyclerView必须具有相同的id... (5认同)
  • 有什么方法可以禁用这些布局的 viewBinding 吗?我已经尝试过工具:viewBindingIgnore =“true” (3认同)