Skip to main content
 首页 » 编程设计

android-layout之当我将 merge> 作为 layout> 的子项时,自动完成功能不起作用

2025年05月04日33luoye11

我的布局中有以下内容;

<?xml version="1.0" encoding="utf-8"?> 
<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:descendantFocusability="beforeDescendants" 
    android:id="@+id/layoutId"> 
 
    <data> 
        <variable name="data" type="com.example.android.Person"/> 
    </data> 
 
        <TextView ... //**YES** Intellisense or autocompletion 
 
    <merge> 
 
        <TextView ... //No Intellisense or autocompletion 
 
        <Spinner ... //No Intellisense or autocompletion 
 
    </merge> 
</layout> 

我尝试在 <merge> 中使用的任何 XML 标签标记不会弹出智能感知或自动完成。

我尝试了以下;

  1. 文件 -> 使缓存无效/重新启动... -> 选择无效并重新启动
  2. 文件 -> 省电模式
  3. 删除 .idea 文件夹和所有 .iml 并重建。

似乎没有任何效果。

Intellisense/autocompletion 在标签外部工作,但不在标签内部。

请问有人有解决办法吗?

临时修复

我改变了<merge>到 Android ViewGroup (在我的例子中是 LinearLayout )然后使用了 ViewStub在我的根布局中。

请您参考如下方法: