简体   繁体   中英

Android GridView Left to Right Scroll

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.

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

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!

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM