"The type Gallery is deprecated", Whats the best alternative?

Omar picture Omar · Aug 8, 2012 · Viewed 22.5k times · Source

I was really surprised that such a Widget gets deprecated.
I want a simple gallery that scrolls left and right, shows a picture on the whole Activity screen, and most important is that you cant swipe more than 1 image in any direction, even if the scroll speed is fast it changes to the next image.

So which Widget should I use? Or should I use a simple ImageView and handle all the swipes and add an animation?

Answer

FoamyGuy picture FoamyGuy · Aug 8, 2012

It states in the docs:

This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library.

HorizontalScrollView will be closer to what you are looking for I think.

I suspect that Gallery was deprecated because it did not properly use convertView with its adapter. Which meant that it had to create a new view for every item which was a drain on performance.

Another option you have is to use the 3rd party created EcoGallery which Joseph Earl created to overcome the issue, this version does recycle its views properly. Unfortunately that pastebin link is the only reference to it I can find online now.