etsy/AndroidStaggeredGrid

The problem of top margin

kyungin-park opened this issue · 0 comments

I had a problem of "top margin".
The margin of column[0] was lower than column[1] for the first time.

I finally found what is the cause of the problem and I am sharing with you guys to prevent having the same problem.

On StaggeredGridView.java file,

//////////// I added two functions below.
private boolean getPositionIsHeaderFooter(final int position) {

    GridItemRecord rec = mPositionData.get(position, null);
    return rec != null ? rec.isHeaderFooter : false;
}

private void removePositionColumn(final int position) {
    GridItemRecord rec = mPositionData.get(position, null);
    if (rec != null) {
        mPositionData.remove(position);
    }
}

And then see if data is not matched to HeaderOrFooter.

@Override
protected void onChildCreated(final int position, final boolean flowDown) {
    super.onChildCreated(position, flowDown);
    if (!isHeaderOrFooter(position)) {

       ///////////// I added a if statement below.
   // remove data which is unmatched to HeaderFooter or General one.
        if(getPositionIsHeaderFooter(position)) {
            removePositionColumn(position);
        }


        // do we already have a column for this position?
        final int column = getChildColumn(position, flowDown);