StaggeredGridView icon indicating copy to clipboard operation
StaggeredGridView copied to clipboard

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

Open vicianm opened this issue 10 years ago • 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();
    //}
}

vicianm avatar Sep 05 '14 13:09 vicianm

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??

hugogz avatar Oct 14 '14 14:10 hugogz

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

JGeraldoLima avatar Aug 06 '15 11:08 JGeraldoLima