在Android Studio中向布局添加文本(初学者)

在Android Studio中向布局添加文本(初学者),android,Android,我试图在我的布局中包含文本,但它并没有出现在设计或蓝图中。在Blueprint中,它只是显示为一个点(在图片中用红色包围)。我尝试在手机上运行的“hello world”应用程序中打开默认文本,但在Android Studio的布局中也出现了同样的问题 我在这个链接上遵循指南: 我已经包括了一个截图作为参考。如果这有帮助,请注意仿真器没有在Android Studio中运行,当我选择Pixel XL 5.5屏幕时,布局/设计屏幕没有完全显示在窗口中(它太大了,我无法向下滚动查看) 我也没有得到蓝

我试图在我的布局中包含文本,但它并没有出现在设计或蓝图中。在Blueprint中,它只是显示为一个点(在图片中用红色包围)。我尝试在手机上运行的“hello world”应用程序中打开默认文本,但在Android Studio的布局中也出现了同样的问题

我在这个链接上遵循指南:

我已经包括了一个截图作为参考。如果这有帮助,请注意仿真器没有在Android Studio中运行,当我选择Pixel XL 5.5屏幕时,布局/设计屏幕没有完全显示在窗口中(它太大了,我无法向下滚动查看)

我也没有得到蓝图中的方形框,如网页图3所示(上面的链接)

编辑:以下是我的活动\u main.xml文件的代码-

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="36dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="TextView"
app:layout_constraintDimensionRatio="h,1:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

您的代码有几个问题。您使用的是ConstraintLayouts,但您的约束有点混淆。在第一个
TextView
中,将
toptopof
约束设置为
parent
,这很好,但底部约束也设置为
topf
parent。将底部约束更改为
bottomobttomof
parent
。像这样:

<TextView
    android:id="@+id/textView"
    android:layout_width="36dp"
    android:layout_height="0dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />


在第二个
TextView
中,您使用的
dimensionRatio
错误。它在
ConstraintLayout
中声明,如果宽度和高度都设置为
MATCH_CONSTRAINT
(又称
0dp
),则只能将此属性与
H
W
一起使用。例如,您将
尺寸比设置为
h,1:3
,但这仅在宽度设置为
0dp
(又称
匹配约束
)时有效。您应该设置宽度
0dp
,显式设置高度,或者将
dimensionRatio
更改为
1:3
,而不是
h,1:3

在此处添加布局xnl文件的代码。显示您的xml文件看起来您没有给出正确的宽度和高度属性。只是猜测而已!如果你共享你的XML文件,我可以在模拟器上看到文本,但在Android Studio上看不到。设计屏幕仍然是空的,蓝图屏幕仍然显示一个小点。有什么建议吗?如果你在模拟器中看到它,而不是在设计屏幕上,那么设计屏幕可能没有显示正确的信息。在设计屏幕的左上角,有一个下拉列表,您可以选择是否显示设计、蓝图或两者,在底部,它应该有一个选项来强制刷新布局。点击它,看看它是否改变了你所看到的。我修正了它。这很奇怪,但它与应用程序的主题有关。出于某种原因,默认的“AppTheme”对我不起作用。