我的应用程序中有一个ListView,它带有一个扩展BaseAdapter的自定义适配器。在我的自定义适配器的getView()方法中,相对布局被夸大,以显示从JSON解析的数据。
在某些情况下,数据包含我想要在行的RelativeLayout的ImageView中加载的图像网址。但默认情况下,此布局不包含第二个ImageView用于此目的。
问题:根据收到的数据以及在我的适配器的getView()方法中膨胀之后,在RelativeLayout中添加子元素(ImageView)的适当方法是什么?下图是膨胀的相对布局:
这就是我在某些情况下需要它的方式(列表的行数取决于数据):
我应该提一下,我已经搜索了很多这个。但是,无法做出有效的方法来决定这一点。
答案 0 :(得分:1)
默认情况下,将图片视图始终放在列表项目布局中,并在需要时将可见性设置为“Gone”,您可以设置图像并更改可见性。
if(imageDisplay){
//set the image and change the visibility as "Visible"
}else{
//set the visibility as "Gone"
}
答案 1 :(得分:1)
Message msg = data[position];
int type = getViewType(msg.type);
switch(type) {
case TEXTVIEW:
if(null == convertView || (null == convertView && convertView.getTag() == TEXTVIEW)) {
convertview = LayoutInflater.from(context).inflate(R.layout.textview);
convertview.setTag(TEXTVIEW);
} else {
convertview = convertview.getTag(TEXTVIEW);
}
//do render your view.
break;
case IMAGEVIEW:
if(null == convertView || (null == convertView && convertView.getTag() == IMAGEVIEW)) {
convertview = LayoutInflater.from(context).inflate(R.layout.imageview);
convertview.setTag(IMAGEVIEW);
} else {
convertview = convertview.getTag(IMAGEVIEW);
}
//do render your view.
break;
}
答案 2 :(得分:0)
这可以帮助您查看ListView Animations
HERE。在那里查看最后一个截图并试用课程ExpandedListView