Asi*_*sim 3 android android-constraintlayout
我得到这条线的红色
<android.support.constraint.ConstraintLayout
Run Code Online (Sandbox Code Playgroud)
和应用程序在打开时崩溃。它工作正常,但现在出现错误:无法解析类android.support.constraint.constraintlayout
我还尝试将依赖项添加到模块 Gradle 文件中,并尝试通过 (add dependencies on androidx.constraints..,) 链接使用建议的修复程序进行修复,但仍然没有运气。我是新来的。请帮忙。
这是主要活动的所有代码:
<?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/background"
tools:context=".MainActivity">
<Button
android:id="@+id/act1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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:text="Bill Calculation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/askOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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:text="What you want to do?"
android:textColor="#00BCD4"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/act1Btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn3"
android:layout_width="130dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="Tax Calc"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/act1Btn" />
<Button
android:id="@+id/btn4"
android:layout_width="142dp"
android:layout_height="46dp"
android:text="Mobile Tax"
app:layout_constraintBottom_toTopOf="@+id/btn3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/act1Btn" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
maven.google.com在build.gradle (Project: Name)文件中声明了存储库:repositories {
google()
}
Run Code Online (Sandbox Code Playgroud)
build.gradle (Module: app)文件中添加库作为依赖项:dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.1.0"
}
Run Code Online (Sandbox Code Playgroud)
ConstrainLayout写:repositories {
google()
}
Run Code Online (Sandbox Code Playgroud)
就我而言,我粘贴了教程中的代码,而不是
<?xml version="1.0" encoding="utf-8"?>
<ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
Run Code Online (Sandbox Code Playgroud)
(就像图里说的那样)或者甚至
<android.support.constraint.ConstraintLayout
. . .
Run Code Online (Sandbox Code Playgroud)
它应该是:
<androidx.constraintlayout.widget.ConstraintLayout
. . .
Run Code Online (Sandbox Code Playgroud)
希望这对某人有帮助!
| 归档时间: |
|
| 查看次数: |
4748 次 |
| 最近记录: |