[英]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.