private void recycleViewHolders ( boolean isRecycleAll ) { if ( mAdapter == null ) { return ; } final List < Integer > headerKeysToRemove = new ArrayList <> ( ) ; // item view holders for ( ViewHolder holder : mViewHolders . getAll ( ) ) { if ( holder != null && ! holder . isDragging ( ) ) { View view = holder . getItemView ( ) ; // recycle view holder if ( isRecycleAll || ( view . getRight ( ) < 0 || view . getLeft ( ) > mSettings . getLayoutWidth ( ) || view . getBottom ( ) < 0 || view . getTop ( ) > mSettings . getLayoutHeight ( ) ) ) { // recycle view holder mViewHolders . remove ( holder . getRowIndex ( ) , holder . getColumnIndex ( ) ) ; recycleViewHolder ( holder ) ; } } } if ( ! headerKeysToRemove . isEmpty ( ) ) { headerKeysToRemove . clear ( ) ; } // column header view holders for ( int count = mHeaderColumnViewHolders . size ( ) , i = 0 ; i < count ; i ++ ) { int key = mHeaderColumnViewHolders . keyAt ( i ) ; // get the object by the key. ViewHolder holder = mHeaderColumnViewHolders . get ( key ) ; if ( holder != null ) { View view = holder . getItemView ( ) ; // recycle view holder if ( isRecycleAll || view . getRight ( ) < 0 || view . getLeft ( ) > mSettings . getLayoutWidth ( ) ) { headerKeysToRemove . add ( key ) ; recycleViewHolder ( holder ) ; } } } removeKeys ( headerKeysToRemove , mHeaderColumnViewHolders ) ; if ( ! headerKeysToRemove . isEmpty ( ) ) { headerKeysToRemove . clear ( ) ; } // row header view holders for ( int count = mHeaderRowViewHolders . size ( ) , i = 0 ; i < count ; i ++ ) { int key = mHeaderRowViewHolders . keyAt ( i ) ; // get the object by the key. ViewHolder holder = mHeaderRowViewHolders . get ( key ) ; if ( holder != null && ! holder . isDragging ( ) ) { View view = holder . getItemView ( ) ; // recycle view holder if ( isRecycleAll || view . getBottom ( ) < 0 || view . getTop ( ) > mSettings . getLayoutHeight ( ) ) { headerKeysToRemove . add ( key ) ; recycleViewHolder ( holder ) ; } } } removeKeys ( headerKeysToRemove , mHeaderRowViewHolders ) ; }
Recycle view holders outside screen