我在 content_main 中的设计视图总是空的。当我尝试放下按钮或 textView 时,它会收缩到左上角

My design view in content_main is always empty. When I try to drop a button or a textView, it will shrink to the top left corner

我正在尝试将一些组件放入 content_main。但是每次我放下它,它都会缩小到左上角。不管我怎么展开,它就是不显示。

我尝试了以下建议:

  1. 正在重新启动我的 Android Studio
  2. 在 styles.xml
  3. 中将 "Base" 添加到父级
  4. 无效cache/restart

这是我的 content_main.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:id="@+id/textView"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

没有错误信息。

可能是因为 ConstraintLayout android:visibility="gone"

你需要删除这一行

android:visibility="gone"

您还需要更正一下按钮对齐方式

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />