首页 > 解决方案 > android模拟器上没有显示TextView?

问题描述

我创建了一个秒表应用程序。当我在我的标签(android os kitkat)上运行这个应用程序时,它工作正常。这是我在选项卡上运行的 android 应用程序的屏幕截图。

标签截图

但是当我在 android vertual 设备(os pie)上运行相同的应用程序时,它不会显示 textView 的内容。这是我的 android 虚拟设备的屏幕截图。

安卓模拟器截图

这是我的 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>

标签: androidandroid-emulator

解决方案


您已将 textview 高度设置为 0dp。那就是问题所在。

解决方案:android:layout_height="wrap_content"


推荐阅读