我有一个图库图片,我想在每个项目(图片)下方添加一个标题。
这是我的实际适配器:
@Override
public View getView(int position, View inputView, final ViewGroup parent) {
ViewHolder holder;
EmergencyCall item = listEmergencyCall.get(position);
if (inputView == null) {
holder = new ViewHolder();
inputView = inflater.inflate(R.layout.gallery_item, null);
holder.imageView = (ImageView) inputView.findViewById(R.id.imageView);
holder.textView = (TextView) inputView.findViewById(R.id.titletxt);
inputView.setTag(holder);
} else {
holder = (ViewHolder) inputView.getTag();
}
holder.imageView.setImageResource(item.getImg());
holder.textView.setText(item.getTitle());
return inputView;
}
public static class ViewHolder {
public RelativeLayout backgroundLayout;
public ImageView imageView;
}
}
这是 xml 文件:
<RelativeLayout
android:id="@+id/background_layout"
android:layout_width="120dp"
android:layout_height="100dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/titletxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</RelativeLayout>
EIDT:现在应该可以了。现在标题已添加到图库图像