0

I'm working on an application which consists of many HorizontalScrollViews. Initially, everything was fine. But as the application is growing, and more images need to be loaded, I'm facing 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. But, I do not want the snap effect. I want it to scroll freely. Thanks

UPDATE: I'm working on Gingerbread.

Harshal Kshatriya
  • 5,630
  • 11
  • 44
  • 60

3 Answers3

1

Consider using Horizontal List View, since it seems your list is actually growing and it is not the intended usage of 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.

There's lots of tutorials about lazy loading and releasing list view's items. For instance, this is one.

Community
  • 1
  • 1
xandy
  • 27,357
  • 8
  • 59
  • 64
0

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.

try reading androids blog post about efficient UI.

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. they're very efficient. :)

good luck

thepoosh
  • 12,497
  • 15
  • 73
  • 132
0

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.

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.

Veer
  • 2,071
  • 19
  • 24