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

时间:2017-07-21 01:06:28

标签: 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

看起来这个名字因某种原因被隐藏了。的 WHY

我附加了一些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));
}

1 个答案:

答案 0 :(得分:2)

您将ImageView身高设置为match_parent,这是问题所在。

您的ImageView已为您的观点留出了所有空间。而TextView低于此值,因此无法显示。

修复ImageView的layout_height属性并重试。