SimpleCursorAdaptor ListView 使用 TextView 和 ImageView 超过 400+行内存问题
这是最好的方法还是还有其他方法?
我扩展 SimpleCursorAdapter 并覆盖 getView(intposition, View ConvertView,ViewGroup 父级)
我检索我的光标,膨胀我的 ImageView 和 TextView,提取数据 从光标并填充 TextView 和 ImageView 在 ImageView 上,我将图像作为 Blob 存储在数据库中。
当我检索 Blob 时,我将其作为 byte[] 取出并将其转换为
位图,如下所示:
Bitmap bmp = BitmapFactory.decodeByteArray(img, 0, img.length);
然后我将 ImageView 上的位图设置为:
iv.setImageBitmap(bmp);
现在我可以向下滚动,没有问题,但是当我开始向后滚动时 在列表中,我遇到了主要的内存问题和零星的跳跃(从什么时候开始) 垃圾收集会赶上)。
谁能告诉我完成这项任务的最佳方法是什么 是?有没有办法回收不在视图中的位图 当接近它们时拉它们并再次显示?
我已经搜索了几个月并尝试了各种技术,但我处于 无法找到能让我完成这项任务的人。
先感谢您。
Is this the best way or are there others?
I extend SimpleCursorAdapter and override getView(int position, View
convertView, ViewGroup parent)
I retrieve my Cursor, inflate my ImageView and TextView, pull the data
from the Cursor and populate the TextView and ImageView
on the ImageView I store my images in the database as Blob's.
When I retrieve my Blob I pull it out as a byte[] and convert it to a
Bitmap as below:
Bitmap bmp = BitmapFactory.decodeByteArray(img, 0, img.length);
Then I set my Bitmap on my ImageView as :
iv.setImageBitmap(bmp);
Now I can scroll down fine no issues but when I start scrolling back
up the list I get major memory issues and sporadic jumping(from when
the garbage collection catches up).
Can anyone tell me what the best way to accomplish this task would
be? Is there a way to recycle the bitmaps that aren't in view and
when approaching them pull them and display again?
I've searched for months and tried various techniques but I'm at a
loss to finding the one that will allow me to accomplish this task.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您观看过此视频吗:http://www.youtube.com/watch?v=N6YdwzAvwOA< /a>
并阅读此线程:如何清除Android中的缓存图像?
基本上你想回收当前不可见的任何图像。
did you watch this video: http://www.youtube.com/watch?v=N6YdwzAvwOA
and read this thread: how to clear the cached images in Android?
Basically you want to recycle any images not currently visible.
我最终将图像移动到外部存储并执行与我之前尝试使用数据库时相同的延迟加载,这有效。不知何故,从数据库尝试执行此操作不允许图像被垃圾收集。
I ended up moving the images to external storage and performing the same lazy loading as I tried in the prior attempts with the database and this worked. Somehow attempting this from the database was not allowing the images to get garbaged collected.