gpt4 book ai didi

android-studio - 为什么我的设计屏幕是灰色的,并且在 Android Studio 中只显示 "androidx.constraintlayout.ConstraintLayout"?

转载 作者:行者123 更新时间:2023-12-04 10:23:45 27 4
gpt4 key购买 nike

我正在尝试通过 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 .约束布局

我的 .xml 文档的开始标记: androidx.constraintlayout .约束布局

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

谢谢

最佳答案

确保您已迁移到 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>

关于android-studio - 为什么我的设计屏幕是灰色的,并且在 Android Studio 中只显示 "androidx.constraintlayout.ConstraintLayout"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60720870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com