Android布局XML报AAPT error mismatched tag标签不匹配错误求助
问题原因
你遇到的AAPT: error: mismatched tag是XML布局的标签闭合、嵌套规则错误导致的,具体有3处问题:
androidx.cardview.widget.CardView标签错误使用了自闭合语法/>,但你需要在它内部嵌套RelativeLayout,应该只写>不添加自闭合斜杠;同时结尾的闭合标签大小写错误,开头的CardView中V是大写,结尾也需要保持一致。RelativeLayout标签同样错误使用了自闭合语法/>,你需要在它内部嵌套ImageView、TextView等子控件,应该改为>。- 嵌套层级错误,RelativeLayout和它内部的所有子控件必须放在CardView的开闭标签之间,不能放在CardView外部。
修复后完整代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.cardview.widget.CardView android:id="@+id/cardview" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:padding="12dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/movieImageID" android:background="@android:color/background_dark" android:layout_width="90dp" android:layout_height="90dp" /> <TextView android:id="@+id/movieTitleID" android:padding="5dp" android:layout_centerHorizontal="true" android:layout_toRightOf="@id/movieImageID" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Movie Title" android:textStyle="bold" /> <TextView android:id="@+id/movieReleaseID" android:padding="5dp" android:layout_toRightOf="@id/movieImageID" android:text="Released" android:layout_below="@id/movieTitleID" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/movieCatID" android:padding="5dp" android:layout_below="@id/movieReleaseID" android:layout_toRightOf="@id/movieImageID" android:text="Category" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout> </androidx.cardview.widget.CardView> </LinearLayout>
内容的提问来源于stack exchange,提问作者Mnaz
相关产品推荐
相关产品推荐

