Android 画廊小部件内存不足问题

发布于 2024-09-30 06:27:00 字数 480 浏览 7 评论 0原文

我有一个画廊小部件,其中包含大约合适的(几乎)全屏图像。图像从 SD 卡加载,一次只能看到一张图像(滚动时接受重叠)。问题是,滚动浏览大约 35 个图像后,我收到 OutOfMemoryError:位图超出 VM 预算。我认为画廊小部件会根据需要处理视图,但我想我要么错了,要么做错了什么。

我使用 CursorAdapter 来加载数据,我注意到每当我滚动到新图像时,都会调用 newView() 和 bindView() 。我认为这意味着原始视图已被处理,但内存不足问题似乎表明相反的情况。我正在使用具有相当多字段的 ViewHolder。

所以我的问题是:

  1. 与 CursorAdapter 一起使用时,图库小部件的行为是否与列表视图不同?
  2. 有没有办法强制回收和/或销毁视图? (或者我可能做错了什么)。
  3. 对于处理这种情况下的内存不足问题,还有其他建议吗?缩小尺寸并不是一个真正的选择,图库应该能够处理无限数量的图像(或至少两倍)。

I have a gallery widget with a about fitfy (almost) full screen images. Images are loaded from SD Card, and only one image is visible at a time (accept for overlap when scrolling). The problem is that after scrolling throught about 35 images I get OutOfMemoryError: bitmap exceeds VM budget. I thought a gallery widget disposed of views as required, but I guess I'm either mistaken or doing something wrong.

I use a CursorAdapter to load data, and I notice that whenever I scroll to new image, both newView() and bindView() is called. I would assume this means that the original view had been disposed of, but the out of memory issue seems to indicate the opposite. I'm using a ViewHolder with quite a few fields.

So my questions are:

  1. Does a gallery widget behave differently than a listview when used with a CursorAdapter?
  2. Is there a way to force recycling and/or desposing of views? (Or what could I be doing wrong).
  3. Other suggestions for dealing with out of memory issues for this scenario? Downscaling is not really an option, and the gallery should be able to deal with unlimited number of images (or at least twice as many).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-10-07 06:27:00

图像尺寸是多少?它会导致问题。尝试以下方法减小图像尺寸:

BitmapFactory.Options o2 = new BitmapFactory.Options();
//Best to use powers of 2.
o2.inSampleSize=2;
BitmapFactory.decodeStream(new FileInputStream(f), null, o2);

What's the image dimension? It will cause the problem. Try this to reduce the image dimension:

BitmapFactory.Options o2 = new BitmapFactory.Options();
//Best to use powers of 2.
o2.inSampleSize=2;
BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文