找不到元素“android.support.constraint.ConstraintLayout"的声明 [英] Cannot find the declaration of element 'android.support.constraint.ConstraintLayout'
问题描述
我创建了一个名为 activity_main(sw50dp)
的 xml 文件,但是当我尝试验证它时,它给了我错误:
错误:(4, 42) cvc-elt.1.a:找不到元素android.support.constraint.ConstraintLayout"的声明.
和
C:\Program Files\Android\Android Studio\lib\idea.jar!\standardSchemas\xhtml1.dtd错误:(26, 3) 文档中根元素之前的标记必须格式正确.
activity_main 文件
<按钮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"机器人:文本=÷"应用程序:layout_constraintEnd_toEndOf="父"应用程序:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"/><按钮android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginEnd="220dp"android:layout_marginStart="100dp"android:background="@drawable/椭圆"机器人:文本=2"应用程序:layout_constraintLeft_toRightOf="@+id/button1"应用程序:layout_constraintStart_toEndOf="@+id/button1"app:layout_constraintTop_toTopOf="@+id/button1"/><按钮android:id="@+id/button1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginEnd="320dp"机器人:layout_marginRight="0dp"android:layout_marginTop="118dp"android:background="@drawable/椭圆"机器人:文本=1"应用程序:layout_constraintLeft_toLeftOf="parent"应用程序:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"/><按钮android:id="@+id/buttonReset"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginEnd="320dp"机器人:layout_marginRight="0dp"android:layout_marginTop="45dp"android:background="@drawable/椭圆"机器人:文本=C"应用程序:layout_constraintLeft_toLeftOf="parent"应用程序:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"/><文本视图android:id="@+id/textNum"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginEnd="100dp"android:layout_marginStart="100dp"<按钮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/椭圆"</android.support.constraint.ConstraintLayout>
activity_main(sw50dp) 文件
我还创建了其他布局文件,例如 activity_main(normal-land).我对他们没有任何问题.
注意:如果资源目录名称不正确,可能会发生此错误.
创建目录名称的最佳过程:
- 正在做:文件 -> 新建 -> Android 资源目录
- 选择:最小屏幕宽度
- 点击>>"并输入[浸入次数]
此外,将这一行添加到 Gradle 文件中可以解决类似的错误:
<预><代码>依赖{...实现 'com.android.support.constraint:constraint-layout:1.1.0'}接着是重新同步.
I have created an xml file called activity_main(sw50dp)
, but when I try to validate it, it gives me the errors:
Error:(4, 42) cvc-elt.1.a: Cannot find the declaration of element 'android.support.constraint.ConstraintLayout'.
and
C:\Program Files\Android\Android Studio\lib\idea.jar!\standardSchemas\xhtml1.dtd
Error:(26, 3) The markup in the document preceding the root element must be well-formed.
activity_main file
<?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>
activity_main(sw50dp) file
<?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">
I have created other layout files as well for example activity_main(normal-land). I didn't have any problems with them.
Note: This error can happen if the resource directory name is incorrect.
Best procedure for creating the directory name:
- Doing: File -> New -> Android Resource Directory
- Choose: Smallest Screen Width
- Tap ">>" and enter [The number of dips]
Also, adding this line to the Gradle file solves similar errors:
dependencies {
...
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}
Followed by a resync.
Google Constraint Layout Sample
这篇关于找不到元素“android.support.constraint.ConstraintLayout"的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!