1
我创建了一个照片库,允许您选择多张照片,但我注意到使用缩略图填充GridView可能会非常缓慢。我用一个定时器:Android中的快速缩略图检索
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
fetchNextThumb();
}
}, 0, 25);
它搜索GridView的儿童没有缩略图(这是我保持禁用),如果它尚未高速缓存中检索从MediaStore正确的拇指,并且在UI线程上执行setImageBitmap():
private void fetchNextThumb()
{
for (int i = 0; i < gridView.getChildCount(); i++)
{
ImageSelectView isv = (ImageSelectView)gridView.getChildAt(i);
if (isv == null)
continue;
if (isv.isEnabled())
continue;
activeThumb = thumbCache.get(isv.getId());
if (activeThumb == null)
{
activeThumb = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), isv.getId(), MediaStore.Images.Thumbnails.MICRO_KIND, null);
thumbCache.put(isv.getId(), activeThumb);
}
activeView = isv;
runOnUiThread(setNextThumb);
return;
}
}
private Bitmap activeThumb;
private ImageSelectView activeView;
private Runnable setNextThumb = new Runnable() {
public void run() {
activeView.setImageBitmap(activeThumb);
activeView.invalidate();
activeView.setEnabled(true);
}
};
起初速度非常快,但在大约50张左右的缩略图被抓住后开始放慢速度。任何人都知道加快缩略图检索的任何技巧?
感谢您的更新!你发现为什么内置画廊与这种方法相比如此之快?我有完全一样的问题。 – Mars 2015-02-04 21:56:22