0

我正在学习 android 开发我的 android studio 的设计视图有这个问题,它显示灰色背景,androidx.constraintLayout.constraintLayout中间有文本

xml 设计视图快照

在此处输入图像描述

现在我尝试了为什么我的设计屏幕灰色并且在 Android Studio 中只显示“androidx.constraintlayout.ConstraintLayout”中所述的解决方案? dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" }在 build.gradle 和android:id="@+id/constraintLayout"我的 xml 文件中添加了

我也尝试过:重建项目,使缓存无效,问题选项卡中提供的解决方案是:

    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

4

1 回答 1

0

我有同样的问题,但我通过删除修复它

implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

并使用

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

只要

我不知道是什么导致了这个问题,但我希望这会对你有所帮助。

于 2021-11-01T06:44:38.230 回答