Android 如何在栅格视图中对图元排序
我有一个网格视图适配器,其中所有内容都包含在以下代码中:Android 如何在栅格视图中对图元排序,android,xml,gridview,Android,Xml,Gridview,我有一个网格视图适配器,其中所有内容都包含在以下代码中: @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View v = convertView; CheckBox check = null; ImageView pic = null; if (convertView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
CheckBox check = null;
ImageView pic = null;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.check_box_and_imageview, null);
}
pic = (ImageView)v.findViewById(R.id.imageView);
check = (CheckBox) v.findViewById(R.id.checkBox);
check.setTag(position);
ImageLoader loader = new ImageLoader(mContext);
//this loads image from given url
loader.DisplayImage(url[position], pic);
return v;
}
在这里,我创建了一个带有复选框和图像视图的视图。这是因为图像视图的大小不同,而gridview通过大小复选框和图像视图进行对齐。但我想按复选框对元素进行排序
为了更好地解释,我想做的事情将显示此图片:
这是我想做的。然而,我的图像视图大小却不尽相同。现在我将说明它的外观:
所以这不适合我。我希望对齐所有复选框和imageview。但只是复选框会在复选框下
那么,这不可能与网格视图有关吗?- 检查convertView是否为空:
- 如果为null,则是时候为这个GridView的元素膨胀一个新视图了。您还可以使用holder模式缓存组成视图(而不是每次都使用findViewById进行搜索)(您使用setTag元素进行膨胀视图,但它是节点数据元素中的一段数据?!?您打算如何处理它?!)