@@ -1526,10 +1526,11 @@ public void onAnimationUpdate(@NonNull ValueAnimator animator) {
15261526 }
15271527
15281528 private int getChildIndexOnOffset (@ NonNull T abl , final int offset ) {
1529+ final int ablTopInset = abl .getTopInset () + abl .getPaddingTop ();
15291530 for (int i = 0 , count = abl .getChildCount (); i < count ; i ++) {
15301531 View child = abl .getChildAt (i );
1531- int top = child .getTop ();
1532- int bottom = child .getBottom ();
1532+ int top = child .getTop () - ablTopInset ;
1533+ int bottom = child .getBottom () - ablTopInset ;
15331534
15341535 final LayoutParams lp = (LayoutParams ) child .getLayoutParams ();
15351536 if (checkFlag (lp .getScrollFlags (), LayoutParams .SCROLL_FLAG_SNAP_MARGINS )) {
@@ -1552,16 +1553,12 @@ private void snapToChildIfNeeded(CoordinatorLayout coordinatorLayout, @NonNull T
15521553 final View offsetChild = abl .getChildAt (offsetChildIndex );
15531554 final LayoutParams lp = (LayoutParams ) offsetChild .getLayoutParams ();
15541555 final int flags = lp .getScrollFlags ();
1556+ final int ablTopInset = abl .getTopInset () + abl .getPaddingTop ();
15551557
15561558 if ((flags & LayoutParams .FLAG_SNAP ) == LayoutParams .FLAG_SNAP ) {
15571559 // We're set the snap, so animate the offset to the nearest edge
1558- int snapTop = -offsetChild .getTop ();
1559- int snapBottom = -offsetChild .getBottom ();
1560-
1561- if (offsetChildIndex == abl .getChildCount () - 1 ) {
1562- // If this is the last child, we need to take the top inset and padding into account
1563- snapBottom += abl .getTopInset () + abl .getPaddingTop ();
1564- }
1560+ int snapTop = -offsetChild .getTop () + ablTopInset ;
1561+ int snapBottom = -offsetChild .getBottom () + ablTopInset ;
15651562
15661563 if (checkFlag (flags , LayoutParams .SCROLL_FLAG_EXIT_UNTIL_COLLAPSED )) {
15671564 // If the view is set only exit until it is collapsed, we'll abide by that
0 commit comments