简体   繁体   English

如何在android studio中使用androidx.constraintLayout文本修复灰色屏幕

[英]How to fix Gray screen with androidx.constraintLayout text in android studio

I am learning android development I have this problem with my design view of my android studio that shows gray background with androidx.constraintLayout.constraintLayout text in the middle我正在学习 android 开发我的 android studio 的设计视图有这个问题,它显示灰色背景,中间有androidx.constraintLayout.constraintLayout文本

xml design view snapshot xml 设计视图快照

在此处输入图片说明

Now i tried solutions stated in Why is my design screen gray and only says "androidx.constraintlayout.ConstraintLayout" in Android Studio?现在我尝试了为什么我的设计屏幕是灰色的并且在 Android Studio 中只显示“androidx.constraintlayout.ConstraintLayout”中所述的解决方案 I added dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" } in build.gradle and android:id="@+id/constraintLayout" in my xml file在 build.gradle 和android:id="@+id/constraintLayout"在我的xml文件中添加了dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" } beta4 dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" }

I also tried: rebuilding the project, invalidating cache and the solution provided in the issue tab which is:我也尝试过:重建项目,使缓存无效以及问题选项卡中提供的解决方案是:

    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.

but found no luck但没有找到运气

here is my gradle.build app dependency:这是我的 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'

} }

here is my xml file:这是我的 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>

here is my gradle.properties这是我的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 version = 3.6.3 running 32 bit SDK version = 26.1.1 ANDROID STUDIO 版本= 3.6.3 运行 32 位 SDK 版本 = 26.1.1

I had the same problem But I fix it by delete我有同样的问题但我通过删除修复它

implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

and use并使用

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

only只要

I don't know what caused that problem, but I hope that will help you.我不知道是什么导致了这个问题,但我希望这会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 'androidx.constraintlayout:constraintlayout' 可以省略? - Why is 'androidx.constraintlayout:constraintlayout' omittable? androidx.constraintlayout:constraintlayout:2.1.0中ImageView布局BUG - ImageView layout BUG in the androidx.constraintlayout:constraintlayout:2.1.0 Androidx Constraintlayout对Android Studio无响应 - Androidx Constraintlayout is unresponsive with Android Studio 如何在 Android Studio 中修复 Flutter 的 AndroidX 兼容性? - How to fix AndroidX compatibility for Flutter in Android Studio? 将 androidx.constraintlayout:constraintlayout lib 更新到 2.0.2 版本后得到 crash isRtl() null 引用 - After updating androidx.constraintlayout:constraintlayout lib to 2.0.2 version got crash isRtl () null reference Android Studio RecyclerView androidx.constraintlayout.widget.ConstraintLayout 无法转换为 android.widget.TextView - Android Studio RecyclerView androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.TextView 由于错误膨胀类 androidx.constraintlayout.widget.ConstraintLayout 导致无法在 Android Studio 上运行我的应用程序 - Can't run my App on Android Studio cause by Error inflating class androidx.constraintlayout.widget.ConstraintLayout Android-屏幕右侧剪切了ConstraintLayout文本 - Android - ConstraintLayout text cut on the right of the screen 如何使ConstraintLayout(androidx.constraintlayout.widget)与MaterialButton(com.google.android.material.button)一起使用? - How to make ConstraintLayout (androidx.constraintlayout.widget) work with MaterialButton (com.google.android.material.button)? 如何强制库使用androidX约束布局而不是android.support约束布局 - How to force library to use androidX constraintlayout instead of android.support constraintlayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM