简体   繁体   English

Android Studio 无法检测布局 R.id 和布局 xml 重构后无法检测标签

[英]Android Studio unable to detect the layout R.id and the layout xml unable to detect tag after refactoring

I'm storing my xml files in a hierarchical manner, subfolders were created based on the modules, to reduce cluttering of xml layout file in the folder.我以分层方式存储我的 xml 文件,基于模块创建子文件夹,以减少文件夹中 xml 布局文件的混乱。 However, after refactoring, the R.id of each view is not detected from the Activity.java and tags in the layout xml is not detected by Android Studio.但是,重构后,在Activity.java中没有检测到每个视图的R.id,Android Studio也没有检测到布局xml中的标签。

I have added the src directory to my build.gradle and it still give me errors.我已将 src 目录添加到我的 build.gradle 中,但它仍然给我错误。

sourceSets {
    main {
        res {
            srcDirs 'src/main/res/layout/login_registration',
                    'src/main/res/layout/store_registration',
                    'src/main/res/layout',
                    'src/main/res'
        }
    }
}

Sample snapshot of the errors:错误的示例快照:

Can't determine type for tag '<FrameLayout android:id="@+id/login_registration_fragment_container" android:layout_height="match_parent" android:layout_width="match_parent" tools:layout_editor_absoluteX="171dp" tools:layout_editor_absoluteY="225dp"/>'

Can't determine type for tag '<include android:layout_height="match_parent" android:layout_width="match_parent" layout="@layout/app_bar_main"/>'

I have followed the guidance from Can the Android layout folder contain subfolders?我遵循了Android 布局文件夹是否包含子文件夹中的指导 . . But it does not work.但它不起作用。 Am I doing something wrong or is there any alternative for managing layout xml files for large application.我是不是做错了什么,或者有没有其他方法可以管理大型应用程序的布局 xml 文件。

EDIT: Thanks to the answer from https://stackoverflow.com/a/64905044/12311798 .编辑:感谢来自https://stackoverflow.com/a/64905044/12311798的回答。 I have fixed the build issue.我已经修复了构建问题。 But the Android Studio still shows errors in both java and xml files.但是 Android Studio 仍然在 java 和 xml 文件中显示错误。 How can I get rid of the warning?我怎样才能摆脱警告? Since the layout resources are detected by gradle.由于布局资源是由 gradle 检测的。

Screenshot of errors in Android Studio: Android Studio 中的错误截图:

当前文件夹结构

在此处输入图片说明

Updated src directory in build.gradle:更新了 build.gradle 中的 src 目录:

sourceSets {
        main {
            res {
                srcDirs  = ['src/main/res/layout/login_registration',
                        'src/main/res/layout/store_registration',
                        'src/main/res/layout',
                        'src/main/res']
            }
        }
    }

Correct format is正确的格式是

sourceSets {
    main {
        res.srcDirs =
        [
                'src/main/res/layout/login_registration',
                    'src/main/res/layout/store_registration',
                    'src/main/res/layout',
                    'src/main/res'
        ]
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM