java - 为什么图片下方没有显示文字?

标签 java android-studio textview android-relativelayout android

我有一个命名图像列表。我希望名字显示为黑色 在图像下。以下是图像+名称对的 .xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:clickable="true"
    android:padding="3dp">

  <ImageView
      android:id="@+id/image"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

  <TextView
      android:id="@+id/text"
      android:text="This is my text"
      android:gravity="center_horizontal"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      android:layout_below="@+id/image"
      android:textColor="#000000"
      android:maxLines="1"
      android:ellipsize="end"/>
</RelativeLayout>

但是,该名称没有出现:

enter image description here

该名称似乎因某种原因被隐藏。 为什么

为了完整性,我附加了一些 Java 代码:

public class ImageNamePair extends RecyclerView.ViewHolder {

    TextView textView;
    ImageView imageView;

    public ImageNamePair(View v) {
        super(v);
        textView = (TextView) v.findViewById(R.id.text);
        imageView = (ImageView) v.findViewById(R.id.image);
    }
}

// In another file we render the images
public void onDataChange(final DataSnapshot dataSnapshot) { 
    viewHolder.textView.setText(getText(dataSnapshot));
    ImageRenderer.renderImage(getImage(dataSnapshot));
}

最佳答案

您将 ImageView 高度设置为 match_parent 这就是问题所在。

您的ImageView已为您的 View 提供了所有空间。并且您的 TextView 位于其下方,因此未显示。

修复ImageView的layout_height属性并重试。

关于java - 为什么图片下方没有显示文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45227399/

相关文章:

java - 带有 Android 和自签名服务器证书的 HTTPS GET (SSL)

java - JUNG 中的布局算法

java - 为什么我的 Bean 在 Junit 测试中不符合 Autowire Candidate 资格?

android - 将 textView 与 Kotlin 中的字符串进行比较

java - 分片环境下如何管理DB连接池?

android - 为什么英特尔 x86 仿真器加速器(HAXM 安装程序)显示与 Windows 不兼容?

android - Android Studio 中更新 Android SDK API 28 的问题

android - 权限被亚行拒绝

android - 为什么当我通过 `android:maxLines` 间接应用它时 `TextAppearance` 被忽略

android - 在 TextView 上对齐图像和文本