private void layoutAttachedAndAppearingViews(RecyclerView.Recycler recycler,RecyclerView.State state){
  if (firstChangedPosition >= firstAttachedItemPosition) {
    int firstAttachedItemPositionTemp=firstAttachedItemPosition;
    int lastAttachedItemPositionTemp=lastAttachedItemPosition;
    int[] spanTopTemp=Arrays.copyOf(spanTop,mSpanCount);
    int[] spanBottomTemp=Arrays.copyOf(spanBottom,mSpanCount);
    topBorder=getPaddingTop();
    bottomBorder=getHeight() - getPaddingBottom();
    spanBottom=Arrays.copyOf(spanTop,mSpanCount);
    updateSpanBottomParameters();
    detachAndScrapAttachedViews(recycler);
    mCurrentPosition=firstAttachedItemPosition;
    lastAttachedItemPosition=firstAttachedItemPosition;
    fakeSpanBottomMin=spanBottomMin;
    fakeSpanBottomMax=spanBottomMax;
    fakeCurrentPosition=mCurrentPosition;
    fakeFirstAttachedItemPosition=firstAttachedItemPosition;
    fakeFirstOneEmptyBottomSpanIndex=firstOneEmptyBottomSpanIndex;
    fakeFirstTwoEmptyBottomSpanIndex=firstTwoEmptyBottomSpanIndex;
    fakeSpanTop=Arrays.copyOf(spanTop,mSpanCount);
    fakeSpanBottom=Arrays.copyOf(spanBottom,mSpanCount);
    fillGridForPreLayout(recycler,state);
    firstAttachedItemPosition=firstAttachedItemPositionTemp;
    lastAttachedItemPosition=lastAttachedItemPositionTemp;
    spanTop=Arrays.copyOf(spanTopTemp,mSpanCount);
    spanBottom=Arrays.copyOf(spanBottomTemp,mSpanCount);
    updateSpanTopParameters();
    updateSpanBottomParameters();
  }
 else {
    topBorder=getPaddingTop() - scrollOffset;
    Arrays.fill(spanTop,topBorder);
    for (int i=0; i < firstChangedPosition; i++) {
      for (int j=0; j < itemLayoutWidthCache.get(i); j++) {
        int spanIndex=itemOccupiedStartSpan.get(i) + j;
        spanTop[spanIndex]+=itemLayoutHeightCache.get(i) * sizePerSpan;
      }
    }
    updateSpanTopParameters();
    bottomBorder=getHeight() - getPaddingBottom();
    spanBottom=Arrays.copyOf(spanTop,mSpanCount);
    updateSpanBottomParameters();
    mCurrentPosition=firstChangedPosition;
    firstAttachedItemPosition=-1;
    lastAttachedItemPosition=-1;
    detachAndScrapAttachedViews(recycler);
    fakeSpanBottomMin=spanBottomMin;
    fakeSpanBottomMax=spanBottomMax;
    fakeCurrentPosition=mCurrentPosition;
    fakeFirstAttachedItemPosition=firstAttachedItemPosition;
    fakeFirstOneEmptyBottomSpanIndex=firstOneEmptyBottomSpanIndex;
    fakeFirstTwoEmptyBottomSpanIndex=firstTwoEmptyBottomSpanIndex;
    fakeSpanTop=Arrays.copyOf(spanTop,mSpanCount);
    fakeSpanBottom=Arrays.copyOf(spanBottom,mSpanCount);
    fillGridForPreLayout(recycler,state);
    firstAttachedItemPosition=fakeFirstAttachedItemPosition;
    spanTop=Arrays.copyOf(fakeSpanTop,mSpanCount);
    spanBottom=Arrays.copyOf(fakeSpanBottom,mSpanCount);
    updateSpanTopParameters();
    updateSpanBottomParameters();
  }
}

private void layoutAttachedAndAppearingViews ( RecyclerView . Recycler recycler , RecyclerView . State state ) { if ( firstChangedPosition >= firstAttachedItemPosition ) { int firstAttachedItemPositionTemp = firstAttachedItemPosition ; int lastAttachedItemPositionTemp = lastAttachedItemPosition ; int [ ] spanTopTemp = Arrays . copyOf ( spanTop , mSpanCount ) ; int [ ] spanBottomTemp = Arrays . copyOf ( spanBottom , mSpanCount ) ; topBorder = getPaddingTop ( ) ; bottomBorder = getHeight ( ) - getPaddingBottom ( ) ; spanBottom = Arrays . copyOf ( spanTop , mSpanCount ) ; updateSpanBottomParameters ( ) ; detachAndScrapAttachedViews ( recycler ) ; mCurrentPosition = firstAttachedItemPosition ; lastAttachedItemPosition = firstAttachedItemPosition ; fakeSpanBottomMin = spanBottomMin ; fakeSpanBottomMax = spanBottomMax ; fakeCurrentPosition = mCurrentPosition ; fakeFirstAttachedItemPosition = firstAttachedItemPosition ; fakeFirstOneEmptyBottomSpanIndex = firstOneEmptyBottomSpanIndex ; fakeFirstTwoEmptyBottomSpanIndex = firstTwoEmptyBottomSpanIndex ; fakeSpanTop = Arrays . copyOf ( spanTop , mSpanCount ) ; fakeSpanBottom = Arrays . copyOf ( spanBottom , mSpanCount ) ; fillGridForPreLayout ( recycler , state ) ; firstAttachedItemPosition = firstAttachedItemPositionTemp ; lastAttachedItemPosition = lastAttachedItemPositionTemp ; spanTop = Arrays . copyOf ( spanTopTemp , mSpanCount ) ; spanBottom = Arrays . copyOf ( spanBottomTemp , mSpanCount ) ; updateSpanTopParameters ( ) ; updateSpanBottomParameters ( ) ; } else { topBorder = getPaddingTop ( ) - scrollOffset ; Arrays . fill ( spanTop , topBorder ) ; for ( int i = 0 ; i < firstChangedPosition ; i ++ ) { for ( int j = 0 ; j < itemLayoutWidthCache . get ( i ) ; j ++ ) { int spanIndex = itemOccupiedStartSpan . get ( i ) + j ; spanTop [ spanIndex ] += itemLayoutHeightCache . get ( i ) * sizePerSpan ; } } updateSpanTopParameters ( ) ; bottomBorder = getHeight ( ) - getPaddingBottom ( ) ; spanBottom = Arrays . copyOf ( spanTop , mSpanCount ) ; updateSpanBottomParameters ( ) ; mCurrentPosition = firstChangedPosition ; firstAttachedItemPosition = - 1 ; lastAttachedItemPosition = - 1 ; detachAndScrapAttachedViews ( recycler ) ; fakeSpanBottomMin = spanBottomMin ; fakeSpanBottomMax = spanBottomMax ; fakeCurrentPosition = mCurrentPosition ; fakeFirstAttachedItemPosition = firstAttachedItemPosition ; fakeFirstOneEmptyBottomSpanIndex = firstOneEmptyBottomSpanIndex ; fakeFirstTwoEmptyBottomSpanIndex = firstTwoEmptyBottomSpanIndex ; fakeSpanTop = Arrays . copyOf ( spanTop , mSpanCount ) ; fakeSpanBottom = Arrays . copyOf ( spanBottom , mSpanCount ) ; fillGridForPreLayout ( recycler , state ) ; firstAttachedItemPosition = fakeFirstAttachedItemPosition ; spanTop = Arrays . copyOf ( fakeSpanTop , mSpanCount ) ; spanBottom = Arrays . copyOf ( fakeSpanBottom , mSpanCount ) ; updateSpanTopParameters ( ) ; updateSpanBottomParameters ( ) ; } }
here we lay out current attached views and appearing views . called when there are removed items out of the top border and in the visible area .
