@@ -219,6 +219,15 @@ protected int determineColumnCount(int gridItemWidth) {
219
219
return columnCount ;
220
220
}
221
221
222
+ /**
223
+ * Calculates and adds the amount of spacing that needs to be between each
224
+ * column, row, and the edges of the RecyclerView. This pays attention to
225
+ * the value from {@link #setSpacingMethod(SpacingMethod)}
226
+ *
227
+ * @param recyclerView The RecyclerView to use for determining the amount of space that needs to be added
228
+ * @param gridItemWidth The requested width for the items
229
+ * @param columnCount The number of columns to display
230
+ */
222
231
protected void updateSpacing (RecyclerView recyclerView , int gridItemWidth , int columnCount ) {
223
232
//Sets the decoration for the calculated spacing
224
233
if (spacerDecoration == null ) {
@@ -241,12 +250,9 @@ protected void updateSpacing(RecyclerView recyclerView, int gridItemWidth, int c
241
250
int freeSpace = usableWidth - (gridItemWidth * columnCount );
242
251
int extraSpace = freeSpace - (2 * minColumnSpacingEdge ) - (separatorCount * minColumnSpacingSeparator );
243
252
253
+ //If we can add spacing, then we need to calculate how much and where to add it
244
254
if (extraSpace >= spacerCount ) {
245
- if (spacingMethod == SpacingMethod .EDGES ) {
246
- edgeSpacing = (freeSpace - (separatorSpacing * spacerCount )) / 2 ;
247
- } else if (spacingMethod == SpacingMethod .SEPARATOR ) {
248
- separatorSpacing = spacerCount == 0 ? 0 : freeSpace / spacerCount ;
249
- } else {
255
+ if (spacingMethod == SpacingMethod .ALL ) {
250
256
int totalMinEdges = minColumnSpacingEdge * 2 ;
251
257
int totalMinSeparators = separatorCount * minColumnSpacingSeparator ;
252
258
@@ -257,6 +263,10 @@ protected void updateSpacing(RecyclerView recyclerView, int gridItemWidth, int c
257
263
258
264
separatorSpacing = spacerCount == 0 ? 0 : totalSeparatorSpace / spacerCount ;
259
265
edgeSpacing = ((freeSpace - totalSeparatorSpace ) / 2 ) + separatorSpacing ;
266
+ } else if (spacingMethod == SpacingMethod .EDGES ) {
267
+ edgeSpacing = (freeSpace - (separatorSpacing * spacerCount )) / 2 ;
268
+ } else { //SEPARATOR
269
+ separatorSpacing = spacerCount == 0 ? 0 : freeSpace / spacerCount ;
260
270
}
261
271
262
272
edgeSpacing -= separatorSpacing ;
@@ -274,6 +284,16 @@ protected void updateSpacing(RecyclerView recyclerView, int gridItemWidth, int c
274
284
spacerDecoration .update (separatorSpacing , matchSpacing ? separatorSpacing : rowSpacing / 2 );
275
285
}
276
286
287
+ /**
288
+ * Performs the actual calculation for determining the number of possible
289
+ * columns by using the {@link #maxColumnCount}, {@link #minColumnSpacingEdge}, and
290
+ * {@link #minColumnSpacingSeparator} in conjunction with the requested width
291
+ * for the items
292
+ *
293
+ * @param recyclerView The RecyclerView to use when determining the possible number of columns
294
+ * @param gridItemWidth The requested width for items to be
295
+ * @return The calculated number of possible columns
296
+ */
277
297
protected int getColumnCount (RecyclerView recyclerView , int gridItemWidth ) {
278
298
int padding = recyclerView .getPaddingLeft () + recyclerView .getPaddingRight ();
279
299
int usableWidth = recyclerView .getWidth () - padding ;
@@ -297,6 +317,13 @@ protected int getColumnCount(RecyclerView recyclerView, int gridItemWidth) {
297
317
return columnCount ;
298
318
}
299
319
320
+ /**
321
+ * Removes the padding previously added to the <code>recyclerView</code>
322
+ * for the edge spacing. If no padding was previously added, then this
323
+ * has no affect
324
+ *
325
+ * @param recyclerView The RecyclerView to remove the padding from
326
+ */
300
327
protected void resetRecyclerPadding (RecyclerView recyclerView ) {
301
328
recyclerView .setPadding (
302
329
recyclerView .getPaddingLeft () - edgeSpacing ,
0 commit comments