我正在学习android开发 我的 android studio 的设计视图有这个问题,显示灰色背景,中间有
androidx.constraintLayout.constraintLayout
文本
xml 设计视图快照
现在我尝试了为什么我的设计屏幕是灰色的,并且在 Android Studio 中只显示“androidx.constraintlayout.ConstraintLayout”? 我在 build.gradle 中添加了
dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" }
并在我的 xml 文件中添加了 android:id="@+id/constraintLayout"
我也尝试过: 重建项目,使缓存无效以及问题选项卡中提供的解决方案:
The following classes could not be instantiated:
- androidx.constraintlayout.widget.ConstraintLayout
(Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.
If this is an unexpected error you can also try to build the project, then manually refresh the layout.
但没有找到运气
这是我的 gradle.build 应用程序依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
这是我的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是我的gradle.properties
org.gradle.jvmargs=-Xmx1024m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
ANDROID STUDIO 版本 = 3.6.3 运行 32 位 SDK版本=26.1.1
我也遇到了同样的问题 但我通过删除修复了它
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
并使用
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
仅
我不知道是什么导致了这个问题,但希望对你有帮助。
将我的实现从实现“androidx.constraintlayout:constraintlayout:2.1.4”更改为实现“androidx.constraintlayout:constraintlayout:1.1.3” 修好了,非常感谢