0

私はAndroid開発を学んでいます.Androidスタジオのデザインビューでこの問題が発生し、灰色の背景にandroidx.constraintLayout.constraintLayoutテキストが中央に表示されます.

xml デザイン ビューのスナップショット

ここに画像の説明を入力

、私のデザイン画面が灰色で、Android Studio で "androidx.constraintlayout.ConstraintLayout" とだけ表示されるのはなぜですか? build.gradle とxml ファイルに追加しました dependencies { implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4" }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 を実行

4

1 に答える 1

0

私は同じ問題を抱えていましたが、削除して修正しました

implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

と使用

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

それだけ

何が問題を引き起こしたのかわかりませんが、お役に立てば幸いです。

于 2021-11-01T06:44:38.230 に答える