maurycyw/StaggeredGridView

SGV.onMeasure() does not recalculate mColumnTops/Bottoms/Lefts when SGV dimension changes

Opened this issue · 2 comments

How to reproduce the problem:

Place SGV e.g. inside LinearLayout together with button B.

When button B is clicked change visibility of B to GONE. This way the SGV dimension is increased but SGV children are not layed out properly.

Quick (dirty) fix: recalculate mColumnTops/Bottoms/Lefts each time SGV.onMeasure() is called:

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (mColumnCount <= 0) {
        boolean isLandscape = getMeasuredWidth() > getMeasuredHeight();
        mColumnCount = isLandscape ? mColumnCountLandscape : mColumnCountPortrait;
    }

    // our column width is the width of the listview
    // minus it's padding
    // minus the total items margin
    // divided by the number of columns
    mColumnWidth = calculateColumnWidth(getMeasuredWidth());

    //if (mColumnTops == null || mColumnTops.length != mColumnCount) {
        mColumnTops = new int[mColumnCount];
        initColumnTops();
    //}
    //if (mColumnBottoms == null || mColumnBottoms.length != mColumnCount) {
        mColumnBottoms = new int[mColumnCount];
        initColumnBottoms();
    //}
    //if (mColumnLefts == null || mColumnLefts.length != mColumnCount) {
        mColumnLefts = new int[mColumnCount];
        initColumnLefts();
    //}
}

Please could you explain with a bit more detail this fix? I'm really interested in it but i have no idea where are some functions like initColumnTops() or calculateColumnWidth in the original SGV. Could you post the whole code please??

just comment these lines didn't work for me :/ The problem occurs only if pull down the list when it is already on the last child. So all the itens disapears or gets messy