【问题标题】:Adding text to layout?在布局中添加文本?
【发布时间】:2016-03-20 22:15:14
【问题描述】:

我有一个横向小屏幕的布局。我在布局中的 TextView 中有一些文本...但 它没有显示出来。我没有定义任何文本大小的字体,也没有设置任何尺寸。然而,textview 的文本没有显示出来:

<LinearLayout android:layout_width="wrap_content"
    android:id="@+id/text_container"
    android:layout_height="wrap_content"
    android:layout_above="@+id/relativeLayout"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="25dp">


    <TextView
        android:layout_width="match_parent"
        android:text="20:00"
        android:layout_height="match_parent"
        />


</LinearLayout>

然而,TextView 是空的...这是显示设计布局屏幕的图像:

这里可以看到文字设置很清晰:

为什么没有显示文字?这非常奇怪,我已经尝试了很多东西,但问题仍然存在。我试过了:

  • 重启 Android Studio
  • 刷新设计视图
  • 构建 -> 清理项目
  • 构建 -> 重建项目

然而,问题仍然存在。感谢您协助完成此问题。

奇怪的是,这仅适用于小景观布局。它在常规布局和小布局中运行良好。这是相同的代码...

【问题讨论】:

  • 为布局设置背景颜色或更改文本颜色
  • @Dhina 我尝试更改文本颜色,但仍然不显示。
  • 我怀疑你的 marginbottom 隐藏了 textview?
  • 我想这就是问题所在......那么,为什么 textview 仍然显示在屏幕上,就像在图像中一样?

标签: android string android-layout android-activity android-studio


【解决方案1】:

我猜你错过了textColor。只需添加这个

android:textColor="#00FF00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

原因

 android:layout_marginBottom="25dp"

layout_marginBottom 是这里的主要罪魁祸首。您的小型设备中没有25dp 的大小。这就是出现问题的原因。

【讨论】:

  • 这个 textView 在一个 LinearLayout 中,它位于一个 relativeLayout 之上,ID 为 relativeLayout
  • @RuchirBaronia 你用的是哪个主题?
  • android:theme="@style/Theme.AppCompat.Light.NoActionBar"
  • @RuchirBaronia 好的。删除android:layout_marginBottom="25dp" 用于测试用例。检查此stackoverflow.com/questions/17543392/textview-is-not-visible
  • @RuchirBaronia 很高兴为您提供帮助。前进。
【解决方案2】:

尝试将布局高度和宽度设置为 match_parent 或某个值,因为 textview 的高度为零,因为它取决于布局/或将 Textview 的高度和宽度更改为 wrap_content

【讨论】:

    猜你喜欢
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    相关资源
    最近更新 更多