简体   繁体   English

如何从Horizo​​ntalScrollView释放屏幕上未显示的图像?

[英]How to free images, which are not displayed on the screen, from HorizontalScrollView?

I'm working on an application which consists of many HorizontalScrollViews. 我正在开发一个包含许多Horizo​​ntalScrollViews的应用程序。 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的LazyAdapterimageLoader实现,并查看他使用的缓存方法。 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/horizo​​ntal-view-swiping-with-viewpager.html这在幕后使用适配器,并且您可以在设置数量很大。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Horizo​​ntalScrollView中获取屏幕宽度 - How to get screen width from within a HorizontalScrollView 如何将图像放在Horizo​​ntalScrollView中? - How to put images in a HorizontalScrollView? 通过社交媒体进行屏幕截图和共享时,无法捕获从API获取并显示在屏幕中的图像/图片。 - Images/Pictures which is fetched from the API and displayed in the screen is not captured while taking screenshots and sharing via social media 使用服务器中的数据(图像)动态填充Horizo​​ntalScrollView - Populate HorizontalScrollView dynamically with data (Images) from the server Horizo​​ntalScrollView从/ drawable文件夹获取图像 - HorizontalScrollView Getting Images from /drawable folder Android从dir中以horizo​​ntalscrollview显示数千张图像 - Android show thousand images in horizontalscrollview from dir 如何在horizo​​ntalScrollView中设置列表视图以填满屏幕? - How to set listviews in horizontalScrollView to fill up the screen? 如何设置图像的Horizo​​ntalScrollView的对齐方式 - How can i set alignment of horizontalScrollView of images 如何启用不在视图中的 HorizontalScrollView 中的特定按钮 - How to enable a specific button in HorizontalScrollView which is not in view 具有四个RelativeLayout的Horizo​​ntalScrollView,每个RelativeLayout占据整个屏幕 - HorizontalScrollView with four RelativeLayout, each of which occupies the entire screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM