我创建了一个名为的 xml 文件activity_main(sw50dp)
,但是当我尝试验证它时,它给了我错误:
错误:(4, 42) cvc-elt.1.a:找不到元素“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.
活动主文件
<?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) 文件
<?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">
我还创建了其他布局文件,例如 Activity_main(normal-land)。我和他们没有任何问题。
注意:如果资源目录名称不正确,可能会发生此错误。
创建目录名称的最佳过程:
- 执行:文件 -> 新建 -> Android 资源目录
- 选择:最小屏幕宽度
- 点击“>>”并输入[浸水次数]
此外,将此行添加到 Gradle 文件可以解决类似的错误:
dependencies {
...
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}
随后进行重新同步。
约束布局版本 https://dl.google.com/dl/android/maven2/com/android/support/constraint/group-index.xml
Google 约束布局示例 https://github.com/googlesamples/android-ConstraintLayoutExamples/archive/master.zip
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)