android - 无法解析类 android.support.constraint.ConstraintLayout

标签 android android-constraintlayout

我得到这条红色的线

<android.support.constraint.ConstraintLayout 
和应用程序在打开时崩溃。
它工作正常,但现在出现错误:无法解析类 android.support.constraint.constraintlayout我还尝试将依赖项添加到模块 Gradle 文件中,并尝试通过 (add dependencies on androidx.constraints..,) 链接修复建议的修复程序,但仍然没有运气。我是新来的。请帮忙。
这是主要 Activity 的所有代码:
<?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>

最佳答案

  • 确保您拥有 maven.google.com build.gradle (Project: Name) 中声明的存储库文件:
  • repositories {
        google()
    }
    
  • 将库添加为 build.gradle (Module: app) 中的依赖项文件:
  • dependencies {
        implementation "androidx.constraintlayout:constraintlayout:2.1.0"
    }
    
  • 使用 ConstrainLayout写:

  • <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <!--    Your Content Here    -->
        
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    关于android - 无法解析类 android.support.constraint.ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64342158/

    相关文章:

    android - 约束集。 java.lang.UnsupportedOperationException:无法转换为尺寸:type = 0x3

    Android - 频繁启动 IntentService

    android - 如何在应用处于草稿状态时在 Google Play Developer Console 中激活应用内产品?

    android - android重新创建Activity和Fragment时java.lang.RuntimeException : Cannot create an instance of class ViewModel,

    java - 为什么我的膨胀后的 ImageView 的高度和宽度都是 0?

    java - 如何在constraintlayout中实现可滚动和放大缩小

    android - marginTop 不适用于 ConstraintLayout 和 wrap_content

    android - 如何提高 Android Studio 应用程序构建速度?

    Android - 如何为约束布局参数设置动画?

    Android ConstraintLayout @dimens 替换为硬编码值