簡體   English   中英

為什么文本未在圖像下方顯示?

[英]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擁有所有視圖空間。 而且您的TextView低於該值,因此不會顯示。

修復ImageView的layout_height屬性,然后重試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM