Open blundell opened 10 years ago
Try making the changes below to onRestoreInstanceState() method in StaggeredGridView.java, hope this helps.
@Override
public void onRestoreInstanceState(Parcelable state) {
GridListSavedState ss = (GridListSavedState) state;
mColumnCount = ss.columnCount;
mNeedSync = true;
boolean isLandscape = false;
int orientation = getContext().getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
isLandscape = true;
} else {
isLandscape = false;
}
int newColCount = isLandscape ? mColumnCountLandscape : mColumnCountPortrait;
if(newColCount == mColumnCount) {
mColumnTops = ss.columnTops;
mColumnBottoms = new int[mColumnCount];
mPositionData = ss.positionData;
}
mColumnCount = newColCount;
super.onRestoreInstanceState(ss);
}
Maybe linked to #62
I think we've got the same.
Reproduction steps:
From this screenshot i think it shows, the
mColumnBottoms
knows it has 1 column but themPositionData
has not updated and still has the old (landscape) 2 column data. Therefore whengetPositionColumn(int position)
is called which referencesmPositionData
it can return a false column number. Leading to theArrayIndexOutOfBoundsException
ingetChildTop
. i.e. position 5 has column 1 when it should have column 0 (portrait == 1 column == mColumnBottoms.length)