Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到元素';android.support.constraint.ConstraintLayout';_Android_Android Layout_Android Constraintlayout - Fatal编程技术网

找不到元素';android.support.constraint.ConstraintLayout';

找不到元素';android.support.constraint.ConstraintLayout';,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,我创建了一个名为activity\u main(sw50dp)的xml文件,但当我尝试验证它时,它会给我错误: 错误:(4,42)cvc elt.1.a:找不到元素“android.support.constraint.ConstraintLayout”的声明 及 活动\u主文件 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="

我创建了一个名为
activity\u main(sw50dp)
的xml文件,但当我尝试验证它时,它会给我错误:

错误:(4,42)cvc elt.1.a:找不到元素“android.support.constraint.ConstraintLayout”的声明

活动\u主文件

<?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"
android:background="@drawable/images"
tools:context=".MainActivity">

<Button
    android:id="@+id/buttonDiv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="320dp"
    android:layout_marginTop="340dp"
    android:background="@drawable/circle"
    android:text="÷"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="220dp"
    android:layout_marginStart="100dp"
    android:background="@drawable/oval"
    android:text="2"
    app:layout_constraintLeft_toRightOf="@+id/button1"
    app:layout_constraintStart_toEndOf="@+id/button1"
    app:layout_constraintTop_toTopOf="@+id/button1" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="320dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="118dp"
    android:background="@drawable/oval"
    android:text="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/buttonReset"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="320dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="45dp"
    android:background="@drawable/oval"
    android:text="C"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textNum"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="100dp"
    android:layout_marginStart="100dp"


<Button
    android:id="@+id/button5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="220dp"
    android:layout_marginStart="100dp"
    android:background="@drawable/oval"


</android.support.constraint.ConstraintLayout>


注意:如果资源目录名称不正确,则可能发生此错误

创建目录名的最佳过程:

  • 操作:文件->新建->Android资源目录
  • 选择:最小屏幕宽度
  • 点击“>>”并输入[浸入次数]
  • 此外,将此行添加到Gradle文件可以解决类似的错误:

    
    dependencies {
        ...
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    }
    
    然后是重新同步


    对于这种情况,您可以添加行

    工具:ignore=“MissingDefaultResource”


    添加到布局目录中布局文件的xml代码,它应该忽略由于缺少运行应用程序不需要的资源而生成的错误

    使用.xml更新您的问题。。。此外,您还应该具有“默认”布局,即sw50dp目录之外的布局。上次文本视图和按钮的语法在activity_main中不正确。他们需要一个结束标记。此外,“活动_主(sw50dp)”格式不正确。它应该以“/>”结尾。那是全部文件吗?不,不是。我不得不删除了一些代码,因为当我试图发布它时,它给了我一个错误:看起来你的帖子大部分是代码。。。类似的东西。如果你能把这个项目放到github或类似的平台上,我会下载它,看看有什么问题……目前的稳定版本是'1.1.0'Oops。更新。谢谢。最好发布XML…添加到Google ConstraintLayout示例的链接。我刚刚把它们作为3.1.1构建。他们都跑得很好。
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    
    dependencies {
        ...
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    }