views:

87

answers:

2

Hi

I have a HorizontalScrollView that has lots of views and images inside it. The issue is that if I have lots of stuff inside it I will get a 'java.lang.OutOfMemoryError: bitmap size exceeds VM budget'

is there any way to use some kind of cache, or add/remove stuff as I move left/right so its not on memory all the time?

Thanks

A: 

Having lots of stuff in a ScrollView means that the entire view hierarchy needs to be populated with very heavyweight objects, thus creating the memory issue.

Any solution you come up with for this problem will basically be reinventing the ListView and GridView widgets.

If you don't mind changing your scroll direction, use those and let these very smart widgets handle the memory management.

CodeFusionMobile
A: 

I think what you want is the existing Gallery widget provided by Android.

Gallery is a layout widget used to display items in a horizontally scrolling list and positions the current selection at the center of the view.

kiswa
thanks. Do you think its a good idea to use Gallery if the things that goes inside the gallery are different (some are imageviews, some are textviews, etc) ??
Daniel Benedykt
It's worth a shot at least. The only way to find out is to try it!
kiswa
Thanks, I think Gallery is good. But I put Listviews inside the gallery and it has some weird jump because I think the gallery and the listview are 'fighting' for the focus. Have you experience this?
Daniel Benedykt
Never tried that. It certainly sounds like that might cause some confusion for Android if it's not sure whether to scroll the Gallery or the ListView. ;) Good luck!
kiswa