@@ -83,6 +83,16 @@ static CarouselOrientationHelper createOrientationHelper(
83
83
/** Returns the y-coordinate of the bottom edge of the parent recycler view. */
84
84
abstract int getParentBottom ();
85
85
86
+
87
+ /**
88
+ * Returns the space occupied by this View in the cross (non-scrolling) axis including
89
+ * decorations and margins.
90
+ *
91
+ * @param child The view element to check
92
+ * @return total space occupied by this view in the perpendicular orientation to current one
93
+ */
94
+ abstract int getDecoratedCrossAxisMeasurement (View child );
95
+
86
96
/**
87
97
* Helper method that calls {@link CarouselLayoutManager#layoutDecoratedWithMargins(View, int,
88
98
* int, int, int)} with the correct coordinates according to the orientation.
@@ -182,13 +192,23 @@ int getParentBottom() {
182
192
return carouselLayoutManager .getHeight ();
183
193
}
184
194
195
+ @ Override
196
+ int getDecoratedCrossAxisMeasurement (View child ) {
197
+ final RecyclerView .LayoutParams params = (RecyclerView .LayoutParams )
198
+ child .getLayoutParams ();
199
+ return carouselLayoutManager .getDecoratedMeasuredWidth (child ) + params .leftMargin
200
+ + params .rightMargin ;
201
+ }
202
+
185
203
@ Override
186
204
public void layoutDecoratedWithMargins (View child , int head , int tail ) {
205
+ int left = getParentLeft ();
206
+ int right = left + getDecoratedCrossAxisMeasurement (child );
187
207
carouselLayoutManager .layoutDecoratedWithMargins (
188
208
child ,
189
- /* left= */ getParentLeft () ,
209
+ /* left= */ left ,
190
210
/* top= */ head ,
191
- /* right= */ getParentRight () ,
211
+ /* right= */ right ,
192
212
/* bottom= */ tail );
193
213
}
194
214
@@ -276,14 +296,24 @@ int getParentBottom() {
276
296
return carouselLayoutManager .getHeight () - carouselLayoutManager .getPaddingBottom ();
277
297
}
278
298
299
+ @ Override
300
+ int getDecoratedCrossAxisMeasurement (View child ) {
301
+ final RecyclerView .LayoutParams params = (RecyclerView .LayoutParams )
302
+ child .getLayoutParams ();
303
+ return carouselLayoutManager .getDecoratedMeasuredHeight (child ) + params .topMargin
304
+ + params .bottomMargin ;
305
+ }
306
+
279
307
@ Override
280
308
public void layoutDecoratedWithMargins (View child , int head , int tail ) {
309
+ int top = getParentTop ();
310
+ int bottom = top + getDecoratedCrossAxisMeasurement (child );
281
311
carouselLayoutManager .layoutDecoratedWithMargins (
282
312
child ,
283
313
/* left= */ head ,
284
- /* top= */ getParentTop () ,
314
+ /* top= */ top ,
285
315
/* right= */ tail ,
286
- /* bottom= */ getParentBottom () );
316
+ /* bottom= */ bottom );
287
317
}
288
318
289
319
@ Override
0 commit comments