AndroidStaggeredGrid icon indicating copy to clipboard operation
AndroidStaggeredGrid copied to clipboard

Grid order not consistent

Open booker0108 opened this issue 11 years ago • 6 comments

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 avatar Jul 22 '14 09:07 booker0108

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; }

booker0108 avatar Aug 08 '14 11:08 booker0108

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.

Bapho avatar Nov 25 '14 13:11 Bapho

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

booker0108 avatar Nov 25 '14 13:11 booker0108

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

Bapho avatar Nov 25 '14 15:11 Bapho

@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; }

booker0108 avatar Nov 25 '14 16:11 booker0108

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;

Bapho avatar Jan 21 '15 11:01 Bapho