Like thousands of other developers, at some point I wanted a horizontal gallery of images. (In my case I wanted it in a page of PageViewer). Then I heard there was a widget called android.wiget.Gallery that was designed just for this situation.
Soon, I began to hear that Gallery was deprecated, and checking StackOverflow, one after the other posts suggested that HorizontalScrollView is the way to go.
I abandon Gallery and setup everything in HorizontalScrollView. I first noticed that HorizontalScrollView is not really a widget in a sense that it can only handle one root layout. Ok, so I implemented the root layout as LinearLayout. Add all my scrollables in the LinearLayout, and realize that HorizontalScrollView also does not have an adapter. No problem, I will cycle through the views, inflating them one by one, and casting off a AsyncTask to load the picture. Works fine on 4.03. Then I ran it on 2.2 and guess what, there were too many async tasks running - so it crashes. Maybe a single AsyncTask that runs through all but there are over 30 images. Now I am starting to consider Gallery again.
But then I hear there is a HorizontalListView. I implemented it, plus an adapter. It works perfectly except now the scrolling is not so smooth (within a page of ViewPager), and it gets stuck after reloading several times(Within a page of ViewPager). I wonder if I should spend more time modifying HorizontalListView or revisit my three other implementations. Maybe I just should not have taken the deprecation so seriously.
Any suggestions?
Epilogue:
In the end, I decided to go stay with the HorizontalScrollView for inside ViewPager, and use the HorizontalListView for other situations. This was due to scrolling efficiencies, lightning fast, and I was able to finally work out a custom adapter by overriding onScroll in the HorizontalScrollView, and in combination with CountDownTimer update the images within a range periodically regardless of speed. Another solution suggested was to use the velocity to start the download, when slow enough. It would be great if the HorizontalListView advoates would check out its behavior inside a ViewPager as I am sure it could be optimized, and improve. This would have been my preferred solution if I had more time. But time is fleeting ..
If you are still intent on working with a HorizontalScrollView
I suggest looking looking here for the layout and here for handling the item selection listener. I don't like this route however as you are essentially just making one giant LinearLayout
inside of the HorizontalScrollView
which can cause memory problems as all of the images persist even while off screen.
Personally I would suggest the using the HorizontalListView
found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With