diff --git a/greedo-layout/src/main/java/com/fivehundredpx/greedolayout/GreedoLayoutManager.java b/greedo-layout/src/main/java/com/fivehundredpx/greedolayout/GreedoLayoutManager.java index 5e144e9..1dd01f4 100644 --- a/greedo-layout/src/main/java/com/fivehundredpx/greedolayout/GreedoLayoutManager.java +++ b/greedo-layout/src/main/java/com/fivehundredpx/greedolayout/GreedoLayoutManager.java @@ -192,6 +192,16 @@ private int preFillGrid(Direction direction, int dy, int emptyTop, detachView(cachedView); } } + //Check if it is scrolled too fast and if so find the row that should be displayed first + //If startTopOffset is greater than zero than that means we are trying to fill the screen + //somewhere below the top part. + if (direction == Direction.UP) { + while (startTopOffset >= -dy / 2 && mFirstVisibleRow != 0) { + mFirstVisibleRow--; + newFirstVisiblePosition = firstChildPositionForRow(mFirstVisibleRow); + startTopOffset -= sizeForChildAtPosition(newFirstVisiblePosition).getHeight(); + } + } mFirstVisiblePosition = newFirstVisiblePosition; @@ -378,8 +388,9 @@ public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerVi if (getChildCount() == 0 || dy == 0) { return 0; } - + //Take top measurements from the top-left child final View topLeftView = getChildAt(0); + //Take bottom measurements from the bottom-right child. final View bottomRightView = getChildAt(getChildCount() - 1); int pixelsFilled = getContentHeight(); // TODO: Split into methods, or a switch case?