首页 > 解决方案 > 为什么我的设计屏幕是灰色的,并且在 Android Studio 中只显示“androidx.constraintlayout.ConstraintLayout”?

问题描述

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

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

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

在此处查看代码和示例图像:https://i.imgur.com/kub2gIH.png

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

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

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

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

谢谢

标签: android-studio

解决方案


可能是您缺少它的库并且无法识别。

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

  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

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


推荐阅读