etsy / AndroidStaggeredGrid

An Android staggered grid view which supports multiple columns with rows of varying sizes.
https://github.com/etsy/AndroidStaggeredGrid
4.76k stars 1.13k forks source link

Grid order not consistent #129

Open booker0108 opened 10 years ago

booker0108 commented 10 years ago

Hi, I am developing an application that using the staggered grid view.

I have to load 4 different size images from server to form a bottom-level grid view which I designed and order the data to do so.

The correct order should be like below:

grid

However, the view is now randomly place the 3rd image each time(sometime on left and sometime on right), and thus it makes the grid view finally in irregular shape.

How can I prevent this issue?

booker0108 commented 10 years ago

Temporary fix for those want simple order from left to right

As the SGV always try to find the shortest column to put the next child, I modified the code to make its ordering in simple left to right order

private int getChildColumn(final int position, final boolean flowDown) { if(position < mColumnCount) return position; else return position%mColumnCount; }

Bapho commented 9 years ago

My views have the same height but i have the same issue. Unfortunately, in my case, the workaround is ordering it from right to left. The left-most view of the last row is empty if the last row isn't completely filled with childrens.

booker0108 commented 9 years ago

@Bapho I am fine with my fix. I just wonder why you don't use official gridview if your views have same dimension?

Bapho commented 9 years ago

@booker0108 I used different dimensions before. Plus headers, footers and variable column counts for landscape and portrait mode.

booker0108 commented 9 years ago

@Bapho

If you want a right to left order, please try below code(I haven't tried it)

private int getChildColumn(final int position, final boolean flowDown) { int newPosition = position%mColumnCount;

return mColumnCount-newPosition; }

Bapho commented 9 years ago

I wanted a left-to-right order but your code isnt working if using headers. So i used this code:

private int getChildColumn( final int position, final boolean flowDown ) {

        return ( position - getHeaderViewsCount() ) % mColumnCount;