leanback/src/main/java/androidx/leanback/widget/StaggeredGridDefault.java
@Override
    public int findRowMin(boolean findLarge, int indexLimit, int[] indices) {
        int value;
        int edge = mProvider.getEdge(indexLimit);
        Location loc = getLocation(indexLimit);
        int row = loc.row;
        int index = indexLimit;
        int visitedRows = 1;
        int visitRow = row;
        if (mReversedFlow) {
            value = edge - mProvider.getSize(indexLimit);
            for (int i = indexLimit - 1; visitedRows < mNumRows && i >= mFirstVisibleIndex; i--) {
                edge -= loc.offset;
                loc = getLocation(i);
                if (loc.row != visitRow) {
                    visitRow = loc.row;
                    visitedRows++;
                    int newValue = edge - mProvider.getSize(i);
                    if (findLarge ? newValue > value : newValue < value) {
                        value = newValue;
                        row = visitRow;
                        index = i;
                    }
                }
            }
        } else {
            value = edge;
            for (int i = indexLimit + 1; visitedRows < mNumRows && i <= mLastVisibleIndex; i++) {
                loc = getLocation(i);
                edge += loc.offset;
                if (loc.row != visitRow) {
                    visitRow = loc.row;
                    visitedRows++;
                    if (findLarge ? edge > value : edge < value) {
                        value = edge;
                        row = visitRow;
                        index = i;
                    }
                }
            }
        }
        if (indices != null) {
            indices[0] = row;
            indices[1] = index;
        }
        return value;
    }
/**
     * Note this method has assumption that item is filled either in the same row
     * next row of last item.  Search until row index wrapped.
     */
Note this method has assumption that item is filled either in the same row
next row of last item.  Search until row index wrapped.
Note this method has assumption that item is filled either in the same row next row of last item . Search until row index wrapped .
@Override
    public int findRowMin(boolean findLarge, int indexLimit, int[] indices) {
        int value;
        int edge = mProvider.getEdge(indexLimit);
        Location loc = getLocation(indexLimit);
        int row = loc.row;
        int index = indexLimit;
        int visitedRows = 1;
        int visitRow = row;
        if (mReversedFlow) {
            value = edge - mProvider.getSize(indexLimit);
            for (int i = indexLimit - 1; visitedRows < mNumRows && i >= mFirstVisibleIndex; i--) {
                edge -= loc.offset;
                loc = getLocation(i);
                if (loc.row != visitRow) {
                    visitRow = loc.row;
                    visitedRows++;
                    int newValue = edge - mProvider.getSize(i);
                    if (findLarge ? newValue > value : newValue < value) {
                        value = newValue;
                        row = visitRow;
                        index = i;
                    }
                }
            }
        } else {
            value = edge;
            for (int i = indexLimit + 1; visitedRows < mNumRows && i <= mLastVisibleIndex; i++) {
                loc = getLocation(i);
                edge += loc.offset;
                if (loc.row != visitRow) {
                    visitRow = loc.row;
                    visitedRows++;
                    if (findLarge ? edge > value : edge < value) {
                        value = edge;
                        row = visitRow;
                        index = i;
                    }
                }
            }
        }
        if (indices != null) {
            indices[0] = row;
            indices[1] = index;
        }
        return value;
    }
@ Override public int findRowMin ( boolean findLarge , int indexLimit , int [ ] indices ) { int value ; int edge = mProvider . getEdge ( indexLimit ) ; Location loc = getLocation ( indexLimit ) ; int row = loc . row ; int index = indexLimit ; int visitedRows = 1 ; int visitRow = row ; if ( mReversedFlow ) { value = edge - mProvider . getSize ( indexLimit ) ; for ( int i = indexLimit - 1 ; visitedRows < mNumRows && i >= mFirstVisibleIndex ; i -- ) { edge -= loc . offset ; loc = getLocation ( i ) ; if ( loc . row != visitRow ) { visitRow = loc . row ; visitedRows ++ ; int newValue = edge - mProvider . getSize ( i ) ; if ( findLarge ? newValue > value : newValue < value ) { value = newValue ; row = visitRow ; index = i ; } } } } else { value = edge ; for ( int i = indexLimit + 1 ; visitedRows < mNumRows && i <= mLastVisibleIndex ; i ++ ) { loc = getLocation ( i ) ; edge += loc . offset ; if ( loc . row != visitRow ) { visitRow = loc . row ; visitedRows ++ ; if ( findLarge ? edge > value : edge < value ) { value = edge ; row = visitRow ; index = i ; } } } } if ( indices != null ) { indices [ 0 ] = row ; indices [ 1 ] = index ; } return value ; }
Note this method has assumption that item is filled either in the same row
 next row of last item.
Note this method has assumption that item is filled either in the same row next row of last item .