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

Why is the text not shown below the image?

我有一个命名图像列表。我希望名字显示为黑色 在图像下。下面是图像+名称对的 .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>

但是名字没有出现:

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

为了完整性,我附上了一些 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 获得了所有 space 的观点。而您的 TextView 低于该值,因此未显示。

修复 ImageView 的 layout_height 属性 并重试。