android 模拟器上没有显示 TextView?
TextView is not showing on android emulator?
我创建了一个秒表应用程序。当我 运行 我的选项卡上的这个应用程序( android os kitkat)它工作正常。这是我的 android 应用 运行ning 在选项卡上的屏幕截图。
tab screenshot
但是当我在 android 虚拟设备(os 饼图)上 运行 相同的应用程序时,它不显示 textView 的内容。这是我的 android 虚拟设备的屏幕截图。
android emulator screenshot
这是我的 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"
tools:context=".StopwatchActivity">
<TextView
android:id="@+id/time_view"
android:layout_width="231dp"
android:layout_height="0dp"
android:layout_marginTop="116dp"
android:layout_marginBottom="58dp"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/start_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="51dp"
android:layout_marginBottom="61dp"
android:text="@string/start"
android:onClick="onClickStart"
app:layout_constraintBottom_toTopOf="@+id/stop_button"
app:layout_constraintStart_toStartOf="@+id/time_view"
app:layout_constraintTop_toBottomOf="@+id/time_view" />
<Button
android:id="@+id/stop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginBottom="53dp"
android:text="@string/stop"
android:onClick="onClickStop"
app:layout_constraintBottom_toTopOf="@+id/reset_button"
app:layout_constraintStart_toStartOf="@+id/start_button"
app:layout_constraintTop_toBottomOf="@+id/start_button" />
<Button
android:id="@+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginBottom="241dp"
android:text="@string/reset"
android:onClick="onClickReset"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/stop_button"
app:layout_constraintTop_toBottomOf="@+id/stop_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
您已将文本视图高度设置为 0dp。就是这个问题。
解决方法:
android:layout_height="wrap_content"
我创建了一个秒表应用程序。当我 运行 我的选项卡上的这个应用程序( android os kitkat)它工作正常。这是我的 android 应用 运行ning 在选项卡上的屏幕截图。
tab screenshot
但是当我在 android 虚拟设备(os 饼图)上 运行 相同的应用程序时,它不显示 textView 的内容。这是我的 android 虚拟设备的屏幕截图。
android emulator screenshot
这是我的 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"
tools:context=".StopwatchActivity">
<TextView
android:id="@+id/time_view"
android:layout_width="231dp"
android:layout_height="0dp"
android:layout_marginTop="116dp"
android:layout_marginBottom="58dp"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/start_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="51dp"
android:layout_marginBottom="61dp"
android:text="@string/start"
android:onClick="onClickStart"
app:layout_constraintBottom_toTopOf="@+id/stop_button"
app:layout_constraintStart_toStartOf="@+id/time_view"
app:layout_constraintTop_toBottomOf="@+id/time_view" />
<Button
android:id="@+id/stop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginBottom="53dp"
android:text="@string/stop"
android:onClick="onClickStop"
app:layout_constraintBottom_toTopOf="@+id/reset_button"
app:layout_constraintStart_toStartOf="@+id/start_button"
app:layout_constraintTop_toBottomOf="@+id/start_button" />
<Button
android:id="@+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginBottom="241dp"
android:text="@string/reset"
android:onClick="onClickReset"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/stop_button"
app:layout_constraintTop_toBottomOf="@+id/stop_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
您已将文本视图高度设置为 0dp。就是这个问题。
解决方法: android:layout_height="wrap_content"