android - 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>
解决方案
您已将 textview 高度设置为 0dp。那就是问题所在。
解决方案:android:layout_height="wrap_content"
推荐阅读
- reactjs - 反应:我怎样才能访问另一个函数返回?
- html - CSS Parallax overflow-y:scroll 让它消失
- vb.net - 加快我的功能 - 动态按钮创建 vb.net
- node.js - 将视频上传到 Instagram 企业帐户总是返回“媒体 ID 不可用”错误消息
- java - 架构公共更新而不是配置一个
- php - 如何创建 localhost 网站可以通过 mariadb 中的链接访问和显示的 pdf 目录?
- javascript - 在 Javascript 说明中使用指针事件进行捏合/缩放
- c# - C# 中的枚举如何选择数字类型的默认值(当没有给出标识符时)?
- java - 如果我有两个以上的实体,我是否需要在 Java Spring 中声明一个 entitymanagerfactory?
- java - 无法启动网络服务器;嵌套异常是 java.lang.IllegalStateException