@@ -83,6 +83,16 @@ static CarouselOrientationHelper createOrientationHelper(
8383 /** Returns the y-coordinate of the bottom edge of the parent recycler view. */
8484 abstract int getParentBottom ();
8585
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+
8696 /**
8797 * Helper method that calls {@link CarouselLayoutManager#layoutDecoratedWithMargins(View, int,
8898 * int, int, int)} with the correct coordinates according to the orientation.
@@ -182,13 +192,23 @@ int getParentBottom() {
182192 return carouselLayoutManager .getHeight ();
183193 }
184194
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+
185203 @ Override
186204 public void layoutDecoratedWithMargins (View child , int head , int tail ) {
205+ int left = getParentLeft ();
206+ int right = left + getDecoratedCrossAxisMeasurement (child );
187207 carouselLayoutManager .layoutDecoratedWithMargins (
188208 child ,
189- /* left= */ getParentLeft () ,
209+ /* left= */ left ,
190210 /* top= */ head ,
191- /* right= */ getParentRight () ,
211+ /* right= */ right ,
192212 /* bottom= */ tail );
193213 }
194214
@@ -276,14 +296,24 @@ int getParentBottom() {
276296 return carouselLayoutManager .getHeight () - carouselLayoutManager .getPaddingBottom ();
277297 }
278298
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+
279307 @ Override
280308 public void layoutDecoratedWithMargins (View child , int head , int tail ) {
309+ int top = getParentTop ();
310+ int bottom = top + getDecoratedCrossAxisMeasurement (child );
281311 carouselLayoutManager .layoutDecoratedWithMargins (
282312 child ,
283313 /* left= */ head ,
284- /* top= */ getParentTop () ,
314+ /* top= */ top ,
285315 /* right= */ tail ,
286- /* bottom= */ getParentBottom () );
316+ /* bottom= */ bottom );
287317 }
288318
289319 @ Override
0 commit comments