【发布时间】:2021-12-15 01:26:51
【问题描述】:
我正在学习安卓开发
我的 android studio 设计视图有这个问题,它显示灰色背景,中间有 androidx.constraintLayout.constraintLayout 文本
xml 设计视图快照
现在我尝试了Why is my design screen gray and only says "androidx.constraintlayout.ConstraintLayout" in Android Studio? 中所述的解决方案
我在 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
【问题讨论】:
-
你为什么不用最新的安卓工作室??为什么SDK版本不是最新的??
-
因为我的机器是32位的
标签: android android-studio android-constraintlayout androidx design-view