android - 向布局添加文本?

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

我有一个横向小屏幕的布局。我在布局的 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 是空的...这是一张显示设计布局屏幕的图像:

enter image description here

这里你可以看到文字设置的很清楚:

enter image description here

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

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

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

奇怪的是,这只适用于布局小景观。它适用于常规布局和小型布局。这是相同的代码...

最佳答案

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

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

原因

 android:layout_marginBottom="25dp"

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

关于android - 向布局添加文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283864/

相关文章:

android - 在 ViewPager 中使用具有相同布局的不同 fragment

java - 如何获取按钮的值并将其显示在edittext上?

java - 使用 POST 将数据从 Java(Android) 发送到 PHP

c# - 在 C# 中允许用户定义的字符串

java - 如何替换字符串中的 XML 标签? (还要检查它是否以 xml 标签开头)

string - 从结尾开始在字符串计数中添加字符

android - 自定义 Android 搜索栏

android - 长按时的圆形按钮背景和提示

android - 如何在 flutter 中打开位置后更新我的位置

android - 以编程方式查找 Android .apk 文件的来源?