You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android链接失败:activity_main.xml中layout_height属性未找到报错求助

解决AAPT报错:layout_height属性未找到的问题

ERROR:C:\Users\aron.kibet\AndroidStudioProjects\Status_Saver22\app\src\main\res\layout\activity_main.xml:2: AAPT: error: attribute layout_height (aka com.example.status_saver22:layout_height) not found。

以下是几个直接有效的排查和解决步骤:

  • 检查XML命名空间声明:确保activity_main.xml的根布局标签开头添加了Android核心命名空间,没有这个声明,系统无法识别layout_height这类标准属性。正确的声明格式如下:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ...>
    
  • 核对属性拼写:确认第2行的layout_height没有拼写错误,比如不要写成LayoutHeight、layout_hight这类错误形式,Android的布局属性是全小写且下划线分隔的格式。

  • 验证标签类型:检查第2行的控件标签是否为Android标准布局控件(如LinearLayout、ConstraintLayout、RelativeLayout等)。如果是自定义控件,需确认是否错误地给它使用了仅标准控件支持的属性,但layout_height属于通用属性,这一步主要排除标签本身的语法错误。

  • 清理重建项目:有时候Android Studio的缓存会导致这类无厘头的属性识别错误,执行Build > Clean Project,完成后再执行Build > Rebuild Project,强制重新编译所有资源。

内容的提问来源于stack exchange,提问作者mes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 21:24:27