Android 画廊小部件内存不足问题
我有一个画廊小部件,其中包含大约合适的(几乎)全屏图像。图像从 SD 卡加载,一次只能看到一张图像(滚动时接受重叠)。问题是,滚动浏览大约 35 个图像后,我收到 OutOfMemoryError:位图超出 VM 预算。我认为画廊小部件会根据需要处理视图,但我想我要么错了,要么做错了什么。
我使用 CursorAdapter 来加载数据,我注意到每当我滚动到新图像时,都会调用 newView() 和 bindView() 。我认为这意味着原始视图已被处理,但内存不足问题似乎表明相反的情况。我正在使用具有相当多字段的 ViewHolder。
所以我的问题是:
- 与 CursorAdapter 一起使用时,图库小部件的行为是否与列表视图不同?
- 有没有办法强制回收和/或销毁视图? (或者我可能做错了什么)。
- 对于处理这种情况下的内存不足问题,还有其他建议吗?缩小尺寸并不是一个真正的选择,图库应该能够处理无限数量的图像(或至少两倍)。
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:
- Does a gallery widget behave differently than a listview when used with a CursorAdapter?
- Is there a way to force recycling and/or desposing of views? (Or what could I be doing wrong).
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像尺寸是多少?它会导致问题。尝试以下方法减小图像尺寸:
What's the image dimension? It will cause the problem. Try this to reduce the image dimension: