在 Android 中向自定义图库视图添加描述
有谁知道如何添加图像的名称或图像的描述,以便它也会在每个图像的投掷时发生变化。
我可以通过获取单独的文本视图并在适配器的 getView() 中膨胀此文本视图来做到这一点。但其效率不高。 所以请帮我找出其他方法...
我的代码:
**public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Vector<ListObjectWithTwoTextAndOneImage> data;
public ImageAdapter(Context c,
Vector<ListObjectWithTwoTextAndOneImage> d)
{
super();
mContext = c;
data = d;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
**fishName.setText(data.get(position).getFirstItem());**
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageBitmap((Utils.getInstance().getImageFromAssets(
PhotoGalleryGallery.this, data.get(position)
.getThumbNailImageUrl() + ".jpg"))); // TODO: change
imageView.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
}**
提前致谢
do anyone know how to add the name of image or a description of the image so that it will also get change on flinging of every image.
i am able to do it by taking a separate text view and inflating this text view in the getView() of the adapter. But its not efficient .
so please help me to find out the other way...
my code:
**public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Vector<ListObjectWithTwoTextAndOneImage> data;
public ImageAdapter(Context c,
Vector<ListObjectWithTwoTextAndOneImage> d)
{
super();
mContext = c;
data = d;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
**fishName.setText(data.get(position).getFirstItem());**
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageBitmap((Utils.getInstance().getImageFromAssets(
PhotoGalleryGallery.this, data.get(position)
.getThumbNailImageUrl() + ".jpg"))); // TODO: change
imageView.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
}**
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢...我也得到了其他替代解决方案..
我刚刚在 get 动态中创建了一个线性布局,然后添加一个图像和文本视图,......
thanks ...i got the other alternate solution also..
I have just created one Linear layout inside the get dynamically and then adding one image and text view,....