diff --git a/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java b/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java index 804dfcfa..83a43033 100644 --- a/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java +++ b/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java @@ -2876,7 +2876,8 @@ private void assignFromView(View anchor) { mPosition = getPosition(anchor); mAssignedFromSavedState = false; assert mFlexboxHelper.mIndexToFlexLine != null; - int flexLinePosition = mFlexboxHelper.mIndexToFlexLine[mPosition]; + int flexLinePosition = + mFlexboxHelper.mIndexToFlexLine[mPosition != NO_POSITION ? mPosition : 0]; mFlexLinePosition = flexLinePosition != NO_POSITION ? flexLinePosition : 0; // It's likely that the view is the first item in a flex line, but if not get the // index of the first item in the same line because the calculation of the flex lines