我想创建一个延迟加载适配器与Gallery
部件一起使用。android图库视图“延迟”与延迟图像加载适配器
也就是说getView()
立即返回一个ImageView
,稍后一些其他机制会异步调用它的setImageBitmap()
方法。我通过创建一个延伸为ImageView
的“懒惰”ImageView
来做到这一点。
public class GalleryImageView extends ImageView {
// ... other stuff here ...
public void setImage(final Looper looper, final int position) {
final Uri uri = looper.get(position);
final String path = looper.sharePath(position);
new Thread(new Runnable() {
@Override
public void run() {
GalleryBitmap gbmp = new GalleryBitmap(context, uri, path);
final Bitmap bmp = gbmp.getBitmap(); // all the work is here
handler.post(new Runnable() {
@Override
public void run() {
if (GalleryImageView.this.getTag().equals(uri)) {
setImageBitmap(bmp);
}
}
});
}
}).start();
}
}
当我在Gallery
中缓慢滚动时,中心图像不断弹出到中心。真的很难解释,但它真的很烦人。我也尝试了相同的方法为一个微调适配器,它在那里完美的作品。
任何想法?
我有同样的问题。滚动是粘性的,整个事情都是左右两边的温差,然后再回到原来的位置。你有没有找到解决方案? – 2011-05-03 21:56:46
您正在使用哪个版本的Android?当您不使用自定义ImageView时会发生此问题吗? 所有图像加载后问题是否会停止? – 2011-05-04 04:48:03
您可以请详细描述什么是您的'画廊' – 2011-05-05 12:54:55