Skip to content

Commit

Permalink
优化RV边界判断
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Aug 13, 2020
1 parent 6cd8684 commit 7a6aae6
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.donkingliang.consecutivescroller;

import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.ScrollingView;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -109,6 +110,8 @@ static boolean canScrollVertically(View view) {
return isConsecutiveScrollerChild(view) && (canScrollVertically(view, 1) || canScrollVertically(view, -1));
}

private static final Rect mBounds = new Rect();

/**
* 判断是否可以滑动
*
Expand Down Expand Up @@ -146,15 +149,17 @@ static boolean canScrollVertically(View view, int direction) {
if (direction > 0) {
for (int i = count - 1; i >= 0; i--) {
View child = recyclerView.getChildAt(i);
if (child.getY() + child.getHeight() > recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
recyclerView.getDecoratedBoundsWithMargins(child, mBounds);
if (mBounds.bottom > recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
return true;
}
}
return false;
} else {
for (int i = 0; i < count; i++) {
View child = recyclerView.getChildAt(i);
if (child.getY() < recyclerView.getPaddingTop()) {
recyclerView.getDecoratedBoundsWithMargins(child, mBounds);
if (mBounds.top < recyclerView.getPaddingTop()) {
return true;
}
}
Expand Down

0 comments on commit 7a6aae6

Please sign in to comment.