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

Material Card View内嵌套Relative Layout报错:标签关闭方式错误

解决MaterialCardView嵌套RelativeLayout的XML标签错误

你的问题出在RelativeLayout的起始标签未正确闭合——在android:layout_height="match_parent"这一行末尾,少了一个>符号,导致XML解析器无法识别标签的结束位置,才会报出"Wrong way to Close this Tag"的错误。

修正后的完整代码如下:

<?xml version="1.0" encoding="utf-8"?>

<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"> <!-- 补上缺失的闭合符号 -->
        <ImageView
            android:layout_width="120dp"
            android:layout_height="170dp"
            android:id="@+id/bookimg"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:src="@mipmap/ic_launcher"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/booktitle"
            android:text="Book Title"
            android:textSize="20sp"
            android:textColor="@color/white"
            android:textStyle="bold"/>
    </RelativeLayout>
</com.google.android.material.card.MaterialCardView>

编写XML布局时的小提醒:

  • 所有起始标签必须以>闭合(自闭合标签用/>)
  • 标签要严格成对出现,避免嵌套层级混乱

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 13:09:27