private ArrayList < Rect > calculateAllBounds ( Paint paint ) { ArrayList < Rect > list = new ArrayList < Rect > ( ) ; //For each views (If no values then add a fake one) final int count = mRecyclerView . getAdapter ( ) . getItemCount ( ) ; final int width = getWidth ( ) ; final int halfWidth = width / 2 ; for ( int i = 0 ; i < count ; i ++ ) { Rect bounds = calcBounds ( i , paint ) ; int w = bounds . right - bounds . left ; int h = bounds . bottom - bounds . top ; bounds . left = ( int ) ( halfWidth - ( w / 2f ) + ( ( i - mCurrentPage - mPageOffset ) * width ) ) ; bounds . right = bounds . left + w ; bounds . top = 0 ; bounds . bottom = h ; list . add ( bounds ) ; } return list ; }
Calculate views bounds and scroll them according to the current index