1
我使用的是自定义列表视图适配器一)视图回收和B)视图持有者对象数据。如何删除从回收的列表视图项
我也成功实现了一个异步图像加载器类来加载位图到列表视图以获得更流畅的滚动体验。
现在这个问题看起来像回收利用,如果我错了,那么正确,但从视觉角度来看,它看起来像回收站显示之前加载的位图,然后加载新的位图,旧图像之间明显的闪烁被新图像替换。
我以前没有注意到这种效果与文本视图。这是回收问题吗?当列表项目退出可视屏幕区域时,是否有办法刮掉旧的位图?
是的,我知道有第三方库负责所有这些影响。如果我无法亲自解决这个问题,那么我会查看一个图书馆。
这是我的名单适配器
// Get the data item for this position
SongObject songObject = list.get(position);
// view lookup cache stored in tag
ViewHolder viewHolder;
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_view_item, parent, false);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
// Set view holder references
viewHolder.album = (TextView) convertView.findViewById(R.id.album);
viewHolder.artist = (TextView) convertView.findViewById(R.id.artist);
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.albumArt = (ImageView) convertView.findViewById(R.id.album_art);
viewHolder.duration = (TextView) convertView.findViewById(R.id.duration);
// Set values to referenced view objects
viewHolder.album.setText(songObject.album);
viewHolder.artist.setText(songObject.artist);
viewHolder.title.setText(songObject.title);
viewHolder.duration.setText(FormatTime(songObject.duration));
// Load album art asynchronously for smoother scrolling experience
new ImageLoader(viewHolder.albumArt).execute(songObject.albumArtURI);
// Return the converted view
return convertView;