我有一个命名图像列表。我希望名字显示为黑色 在图像下。以下是图像+名称对的 .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
已为您的 View 提供了所有空间。并且您的 TextView
位于其下方,因此未显示。
修复ImageView
的layout_height属性并重试。
关于java - 为什么图片下方没有显示文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45227399/