Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GridView load items vertically

Is it possible to load items in GridView with vertical orientation? I mean...

Normal situation - 3 columns

enter image description here

-----------------------------             
1      |  2      |    3
-----------------------------
4      |  5      |    6

enter image description here

Desired situation - 3 columns

-----------------------------              
1      |  3      |    5
-----------------------------
2      |  4      |    6

Thanks in advance!

like image 911
jzafrilla Avatar asked Nov 27 '12 09:11

jzafrilla


2 Answers

I don't think this is possible at all.

Reason ::

  • There is technical glitch doing this since we want to scroll items vertically. And also the rendering items on the screen is also vertical direction. In this case we can not complete the calculation we need to do in the onLayout and onMeasure Method of the GridView.
  • If try another way i.e some of us has suggested that snuffle the datasource as [1,5,2,6,3,7,4,8, ...] but in this case what would be shuffle algorithm?
  • When user flings vertically then how can you calculate how many items we need to render vertically and when to switch to next column to render the other items. there is no such mathematical formula for it.

I did some work on this and came to this conclusion.Hope this make unanswered question answered.

like image 110
Ashwin N Bhanushali Avatar answered Oct 23 '22 12:10

Ashwin N Bhanushali


If you are using GridLayoutManager with RecyclerView, easy way to fill vertically data first is :

GridLayoutManager lLayout_artist = new GridLayoutManager(getActivity(),3,GridLayoutManager.HORIZONTAL, false);

You can change orientation of GridLayoutManager as per your requirement.

like image 42
Abhilasha Avatar answered Oct 23 '22 13:10

Abhilasha