我有一个命名图片列表。我希望名称显示为黑色 在图像下。下面是图像+名称对的.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>
但是,名称不会出现:
看起来这个名字因某种原因被隐藏了。的 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));
}
答案 0 :(得分:2)
您将ImageView
身高设置为match_parent
,这是问题所在。
您的ImageView
已为您的观点留出了所有空间。而TextView
低于此值,因此无法显示。
修复ImageView
的layout_height属性并重试。