Sebastian Nowak
Sebastian Nowak

Reputation: 5717

Android gallery of drawables

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:

Upvotes: 0

Views: 458

Answers (1)

Frank Sposaro
Frank Sposaro

Reputation: 8531

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

Upvotes: 2

Related Questions