Android horizontal listview library with item scroll
4 min read
With all the crazy designers out there, we developers are often faced with having to program custom interfaces and doing magic with our code. One of the things still not supported by default by Android are horizontal ListViews. There is an option of using a horizontal ScrollView, but that doesn’t really make sense because we would have to fill it dynamically, and also it would eat our resources.
(The pulse news app has a somewhat similar idea, like we had to build)
The problem Profico encountered was worse than only making horizontal ListView, We had to make each of the items vertically scrollable. In the end we succeeded to solve the entire concept by using Horizontal Scroll View lib we found on the web, by using our brains, and some luck 🙂 The client this is build for is one of our regional telecom operators, and the usage is to display mass informations, so views reusability optimization had to be considered with much caution;
Actually two years ago I encountered a somewhat similar problem of having to make each item in one ListView to be horizontally scrollable. That one was solved by overriding the Androids default Gallery plugin inside each list item. If you want to learn more about that solution, leave a comment or contact me whatsoever and I can send you the code snippet or make another post.
What is the best Android Horizontal ListView lib?
Of course we didn’t know the answer to this question, so we decided to google around and found quite a few of them. The only one we found to be really good and mostly completed was by Lucas Rocha. Lucas thanks, and here is a link to his lib: TwoWay Lib.
Using this HorizontalListView lib is actually easy. You download the lib, add is as a library project in Eclipse (add project from existing sources, right click on the project -> use as Library Project), and then add it as a Library for your project in its project properties.
Add it to your layout file via XML:
Scroll the items vertically
Now all you have to are the standard ListView operations. Make an adapter that extends BaseAdapter and attach it to the above Horizontal Scroll View. To be able to scroll each horizontal item vertically, we simply inflated a ScrollView containing a LinearLayout to each item.
What we inflate to the list items:
In the end, Profico had a cool new widget, and our client was thrilled to have the app made exactly as the designers wanted!
So this would be our way of implementing a horizontal listview with vertically scrollable items. It is based on existing libs in both the open community and some android widgets. Problems we were afraid to encounter was the swipe handling by the android, and everything is actually working just fine on almost any device. Some of them have problems with exact event processing, but we solved that problem too. Ask in comments if you would like to know how!
Web something-something @ Profico
We shape our core capabilities around lean product teams capable of delivering immense value to organisations worldwide