0

I'm creating a simple Gallery of drawables - each of them is almost the size of a screen, so they require quite much memory. For each entry I'm creating a custom LinearLayout with ImageView and TextView for the title. As most of you know, android Gallery doesn't recycle views so it gallery will crash easily on low-memory phones (after loading 4 drawables on 16mb ram limit, in my case).

Here's the simple question - how do you implement such gallery, so it won't run out of the memory? How do you recycle these images? A working code example would be great.

Few notes:

  • inSampleSize isn't a way to go, I can't scale these images down

  • Calling recycle() on Drawable's loaded from resource is impossible, as it will crash on Android 4.0+ (it will recycle the drawable in their internal cache)

  • Don't ask me to post the code, as there is no.

Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107

1 Answers1

2

You shouldn't be using Gallery because it's deprecated. Especially since there isn't any code written so far. The documentation suggests using a HorizontalScrollView or ViewPager.

I feel a ViewPager is what your looking for because it will only keep at most 3 pictures in memory and handels all the recycling for you. Here is a post with more information about how to implement one android viewPager implementation

Community
  • 1
  • 1
Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
  • Thank you for your answer. ViewPager won't work for me, as I need part of the neighboor images to be visible too. I guess I'll just have to go with HorizontalScrollView. – Sebastian Nowak Aug 01 '12 at 17:11
  • Ahh. Yes. I would check out the code for the People application introduced in 4.0. When you view a ContactDetails your able to see some of their status on the right and then when you swipe you it scrolls and snaps. This was down with a HSV plus some snapping logic. – Frank Sposaro Aug 01 '12 at 17:17