2

Is it possible to make a GridView scroll from left to right instead of top to bottom? I want a view that works essentially exactly like a GridView but performs this left to right scrolling instead of the usually top to bottom. Maybe there is a way to create the same effect using a different view type?

Any help would be appreciated.

w.donahue
  • 10,790
  • 13
  • 56
  • 78

3 Answers3

5

Implementing a horizontally scrolling GridView involves copying a few of the Android source code classes into your codebase (AdapterView, AbsListView, GridView, ScrollBarDrawable) and adding in code to handle the horizontal code. This is mainly copying some of the code and changing top to left, bottom to right, etc. The main reason for having to copy instead of extending is the final nature of those classes.

I implemented this a while ago and finally got around to pushing to github: https://github.com/jess-anders/two-way-gridview

Jess Anders
  • 968
  • 1
  • 8
  • 11
  • Hello, I was going through your library and it doesn't work properly. I would be very happy if you could take a look at my question: http://stackoverflow.com/questions/17504040/twoway-gridview-library-doesnt-work-properly Thanks! – idish Jul 06 '13 at 14:52
  • Make sure you are using my version of it and not one of the forked versions. I just downloaded a fresh copy from github and it works fine. – Jess Anders Jul 09 '13 at 13:57
2

If you want to have exactly the same behaviour of GridView with only the change of scrolling, then my proposal would be to extend GridView to a custom ViewGroup and make the required changes. If you just need horizontal scrolling, then HorizontalScrollView is perfect for such cases. Hope this helps!

Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54
  • Do you think using a GalleryView with a custom view as the "image" may create the effect I am looking for? – w.donahue Sep 10 '11 at 20:39
1

This may be very late to the game, but after landing on this page multiple times while trying to fix problems in my code that uses the two-way-gridview library, I think it's worthwhile to note that I wrote a simple app and tutorial for this library. The tutorial explains how to get the library up and running and the app shows how to get the correct spacing and display. Sincerely hope it helps.

http://spragucm.wordpress.com/2013/11/17/android-horizontal-and-vertical-gridview-tutorial/

Chris Sprague
  • 3,158
  • 33
  • 24
  • That link is not working for me, can you post the solution here. – Fiver Nov 18 '13 at 20:15
  • 1
    I just fixed the link. Please try again because the tutorial is too long to post as is describing the many problems with using the library. If you want the the example code you can just get it from GitHub:https://github.com/spragucm/Horizontal-and-Vertical-GridViews-Example – Chris Sprague Nov 18 '13 at 22:25
  • I was using your tutorial and @Jess Anders' library. However, I wasn't able to get the `OnItemClickListener` to fire with the grid items. Is that possible? Or do I have to attach a click handler to one view in the `getView` method in the adapter. – randomor May 08 '14 at 16:21
  • My preference is to implement an onClickListener in the child view. But, you could also attach an onClickListener in the adapter when first inflating a child - so that you only have a listener object per view. As for onItemClickListener, I don't know. I haven't tried it with Anders' TwoWayGridView – Chris Sprague May 12 '14 at 23:13
  • Actually, just use com.jess.ui.TwoWayAdapterView.OnItemClickListener instead of android.widget.AdapterView.OnItemClickListener I just tried it and it worked for me. – Chris Sprague May 23 '14 at 21:58