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
相关产品推荐
相关产品推荐

