Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FlowLayoutManager.java #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ private int fill(RecyclerView.Recycler recycler, RecyclerView.State state, int d
}
//添加完后,判断是否已经没有更多的ItemView,并且此时屏幕仍有空白,则需要修正dy
View lastChild = getChildAt(getChildCount() - 1);
if (getPosition(lastChild) == getItemCount() - 1) {

View firstVisibleChild = getChildAt(0);
//要做底部修复,还要满足下面第一个条件:第一个显示的View的top在屏幕之外
if (firstVisibleChild.getTop() < 0 && getPosition(lastChild) == getItemCount() - 1) {
int gap = getHeight() - getPaddingBottom() - getDecoratedBottom(lastChild);
if (gap > 0) {
dy -= gap;
Expand Down Expand Up @@ -227,9 +230,13 @@ public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerVi
View lastChild = getChildAt(getChildCount() - 1);
if (getPosition(lastChild) == getItemCount() - 1) {
int gap = getHeight() - getPaddingBottom() - getDecoratedBottom(lastChild);
if (gap > 0) {


View firstVisibleChild = getChildAt(0);
//当前显示的第一个View的top小于零,说明该recyclerview发生了滚动,可以做底部修复
if (gap > 0 && firstVisibleChild.getTop() < 0) {
realOffset = -gap;
} else if (gap == 0) {
} else if (gap == 0 || firstVisibleChild.getTop() >= 0) {//当前第一个显示的top大于等于0,并且最后一个显示的就是最后一个,那一定不需要滚动了,即使gap!=0,也不需要修复
realOffset = 0;
} else {
realOffset = Math.min(realOffset, -gap);
Expand Down