【问题标题】:Resource compilation failed error: mismatched tag资源编译失败错误:标签不匹配
【发布时间】:2019-05-15 12:40:26
【问题描述】:

Android 资源编译失败 C:\Users\TTP\AndroidStudioProjects\TicCrossGame\app\src\main\res\layout\activity_main.xml:94:错误:标签不匹配。

我检查关闭标签但无法理解错误,因为我检查了所有关闭标签但仍然错误

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v7.widget.GridLayout
        android:id="@+id/gridView"
        android:layout_width="395dp"
        android:layout_height="395dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/grid"
        app:columnCount="3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:rowCount="3" >



        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="125dp"
            android:layout_height="126dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
             />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="125dp"
            android:layout_height="126dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            app:srcCompat="@drawable/cross" />

    </android.support.v7.widget.GridLayout>

</android.support.v7.widget.GridLayout>


</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 删除重复的结束标签
  • 问题是你关闭了两次GridLayout标签,无论如何,你能描述一下你希望你的布局是什么样子吗?可能有更好的方法而不是使用 GridLayout

标签: java android android-layout


【解决方案1】:

您有两个关闭的 GridLyout 标记。删除 XML 文件底部的其中一项:

    </android.support.v7.widget.GridLayout>

【讨论】:

    【解决方案2】:

    GridLayout 有两个结束标记,只需删除其中一个,您的代码就可以正常工作。像下面这样:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <android.support.v7.widget.GridLayout
            android:id="@+id/gridView"
            android:layout_width="395dp"
            android:layout_height="395dp"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/grid"
            app:columnCount="3"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:rowCount="3" >
    
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="125dp"
                android:layout_height="126dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                 />
    
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="125dp"
                android:layout_height="126dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                app:srcCompat="@drawable/cross" />
    
        </android.support.v7.widget.GridLayout>
    
    </android.support.constraint.ConstraintLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多