[英]How to free images, which are not displayed on the screen, from HorizontalScrollView?
I'm working on an application which consists of many HorizontalScrollViews. 我正在开发一个包含许多HorizontalScrollViews的应用程序。 Initially, everything was fine.
最初,一切都很好。 But as the application is growing, and more images need to be loaded, I'm facing OutOfMemoryError.
但是随着应用程序的增长以及需要加载更多图像,我面临着OutOfMemoryError。 This is because I'm running out of native memory.
这是因为我的本机内存用完了。 Therefore, I want to release those views which are not visible on the screen, just like ViewPager.
因此,我想释放那些在屏幕上不可见的视图,就像ViewPager一样。 But, I do not want the snap effect.
但是,我不需要捕捉效果。 I want it to scroll freely.
我希望它自由滚动。 Thanks
谢谢
UPDATE: I'm working on Gingerbread. 更新:我正在做姜饼。
Consider using Horizontal List View , since it seems your list is actually growing and it is not the intended usage of ScrollViews. 考虑使用“ 水平列表视图” ,因为似乎您的列表实际上正在增长,而不是ScrollViews的预期用途。 A ScrollView is suppose to have limited, and most probably static amount of child because it does not intended to dynamic release or create views.
假定ScrollView具有有限的子级,并且很可能是静态子级,因为它不打算动态发布或创建视图。
There's lots of tutorials about lazy loading and releasing list view's items. 关于延迟加载和释放列表视图的项目,有很多教程。 For instance, this is one .
例如, 这是一个 。
if I recall correctly, Images that are not on the screen are not in memory. 如果我没记错的话,屏幕上没有的图像不在内存中。 in anyways, working with multipul ScrollViews is very bad for performance.
无论如何,使用multipul ScrollViews会降低性能。
try reading androids blog post about efficient UI . 尝试阅读有关有效UI的 android 博客文章 。
it seems to me that working with a hashmap for the files and with a gallery widget instead of scroll views will be faster for the user. 在我看来,为用户使用文件的哈希图和图库小部件(而不是滚动视图)会更快。
look at the imageLoader
implementation of fedorvlasov's LazyAdapter and look at the caching methods he uses. 查看fedorvlasov的LazyAdapter的
imageLoader
实现,并查看他使用的缓存方法。 they're very efficient. 他们非常有效率。 :)
:)
good luck 祝好运
What you are looking is Lazy Loading of images on horizontal scrollview. 您正在寻找的是在水平滚动视图上延迟加载图像。 I am not sure if it is possible to lazy load the scrollview.
我不确定是否可以延迟加载scrollview。
Maybe you can use a ViewPager http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html This uses an adapter behind the scenes and you can do the trick where you set the count to a very large number. 也许您可以使用ViewPager http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html这在幕后使用适配器,并且您可以在设置数量很大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.