Search code examples
androidandroid-listviewhorizontal-scrollingandroid-scrollviewvertical-scrolling

Android - Horizontal Scrolling Views Inside Vertically Scrolling View


On the Android, I would like to implement the following type of scrolling grid of thumbnails.

Top two rows scrolls horizontally... and, the whole page including the top two rows scrolls vertically.

Both of the horizontal rows will dynamically load additional images as they are scrolled horizontally... Also, the grid will dynamically load as it is scrolled vertically. (total number of items unknown ahead of time)

The issues I am concerned about are:

  1. That horizontal swiping and vertical swiping will both work together nicely.
  2. That view recycling will work for all sets of scrolling views.
  3. Even if there were, say, 8 horizontal rows such that the bottom grid wasn't initially visible that it would still be able to be scrolled vertically.
  4. What type of views would you recommend for each of the parts of this screen (e.g. ListView, ScrollView, etc...)?
  5. What issues might I need to deal with (e.g. passing swipes up to parent views, etc...)?

Thank you... just getting starting on my Android coding adventures!

sample grid view
(source: brianrice.com)


Solution

  • So for your first two views I would recommend you using HorizontalListView, then for other items, if they are always 6 squares in a row, create some simple LinearLayout with horizontal orientation and 6 inner views. As for the whole layout use ordinary ListView.

    There are really nothing special in using HorizontalListView inside ListView because they scroll on different axis, however in your adapter you would have to implement getItemViewType(int position) and getViewTypeCount(), because you have two different types of views in your layout, using this methods android knows what kind of views to supply for reuse in your convertView in getView(int position, View convertView, ViewGroup parent). And using this mechanism - view recycling would work perfectly, because it would create at most 2 HorizontalListView and about 8 other view items.