我正在使用带有大量图像的stickyheaders gridview,并且标题是文本。在任何给定时间,我的屏幕上都有 10 到 20 张图像。我正在使用视图模式来重用单元格。
然而,很多时候细胞没有被重复使用——为什么?此外,每个单元格被调用两次 - 为什么?
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Photo photo = getItem(position);
ViewHolder viewHolder = null;
if (convertView == null ) {
Log.d(TAG, "convertview is null :"+position);
convertView = mInflater.inflate(R.layout.item_photo_grid, parent, false);
viewHolder = new ViewHolder();
viewHolder.imageView = (ImageView) convertView.findViewById(R.id.photo);
viewHolder.selected = convertView.findViewById(R.id.selected);
convertView.setTag(viewHolder);
}
else {
Log.d(TAG, "convertview is resused :"+position);
viewHolder = (ViewHolder) convertView.getTag();
}
frameLoader.pauseOnFling(isFlinging);
frameLoader.pauseOnScroll(isScrolling);
frameLoader.setMaxItems(getVisiblePhotoCount());
frameLoader.displaySmallImage(photo, viewHolder.imageView);
if (mSelectedItems.contains(photo)) {
viewHolder.selected.setVisibility(View.VISIBLE);
}
else {
viewHolder.selected.setVisibility(View.GONE);
}
return convertView;
}
这就是日志输出的样子: