【问题标题】:Why is my design screen gray and only says "androidx.constraintlayout.ConstraintLayout" in Android Studio?为什么我的设计屏幕是灰色的,并且在 Android Studio 中只显示“androidx.constraintlayout.ConstraintLayout”?
【发布时间】:2020-03-17 10:52:38
【问题描述】:

我正在尝试通过 CodingInFlow 在 YouTube 上关注 Android Studio 开发的播放列表。

我正在尝试关注此视频,但我遇到了问题... https://www.youtube.com/watch?v=-sPOtGqd5OA&list=PLrnPJCHvNZuBtcos16XJnfFx2fSUOyW_-&index=9

我的设计屏幕只是显示为一个灰色框,我收到“androidx.constraintlayout.ConstraintLayout(找不到类)”的错误。

在此处查看代码和示例图片:

在视频中,他没有使用 AndroidX,而且他的开始标签与我在 .xml 文件中的标签不同。

他的 .xml 文档的开始标签:android.support.constraint.ConstraintLayout

我的 .xml 文档的开始标签:androidx.constraintlayout.ConstraintLayout

我该如何解决这个问题,以便设计显示在灰色框当前所在的位置?

谢谢

【问题讨论】:

    标签: android-studio


    【解决方案1】:

    确保您已迁移到androidx

    https://developer.android.com/jetpack/androidx/migrate

    将此行添加到 build.gradle

    dependencies {
        implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"
    }
    

    在你的 xml 中

    <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

      【解决方案2】:

      这可能是您缺少它的库而无法识别。

      打开你的 build.gradle (app) 并添加:

        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      

      关于“androidx”库的视频有点旧,所以他的标签与你的不同。所以你必须添加支持它的库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-22
        • 2018-12-10
        • 1970-01-01
        • 2019-07-13
        • 1970-01-01
        • 2021-11-01
        • 2020-11-16
        • 1970-01-01
        相关资源
        最近更新 更多