Skip to content

Commit

Permalink
优化SmoothScroll速度;修复bug。
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Jun 30, 2021
1 parent 4ac4671 commit 310a0bd
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
sortViews();
}

@Override
public void requestLayout() {
super.requestLayout();
}

private void sortViews() {
List<View> list = new ArrayList<>();
int count = getChildCount();
Expand Down Expand Up @@ -844,7 +849,10 @@ private boolean canScrollVertically() {
@Override
protected int getChildDrawingOrder(int childCount, int drawingPosition) {
if (mViews.size() > drawingPosition) {
return indexOfChild(mViews.get(drawingPosition));
int index = indexOfChild(mViews.get(drawingPosition));
if (index != -1) {
return index;
}
}
return super.getChildDrawingOrder(childCount, drawingPosition);
}
Expand Down Expand Up @@ -942,6 +950,17 @@ private void fling(int velocityY) {
@Override
public void computeScroll() {
if (mScrollToIndex != -1 && mSmoothScrollOffset != 0) {

if (mSmoothScrollOffset > 0 && mSmoothScrollOffset < 200){
// 逐渐加速
mSmoothScrollOffset += 5;
}

if (mSmoothScrollOffset < 0 && mSmoothScrollOffset > -200){
// 逐渐加速
mSmoothScrollOffset -= 5;
}

// 正在平滑滑动到某个子view
dispatchScroll(mSmoothScrollOffset);
invalidate();
Expand Down Expand Up @@ -2171,9 +2190,9 @@ public void smoothScrollToChildWithOffset(View view, int offset) {
mScrollToIndexWithOffset = offset;
setScrollState(SCROLL_STATE_SETTLING);
if (scrollOrientation < 0) {
mSmoothScrollOffset = -200;
mSmoothScrollOffset = -50;
} else {
mSmoothScrollOffset = 200;
mSmoothScrollOffset = 50;
}
invalidate();
}
Expand Down

0 comments on commit 310a0bd

Please sign in to comment.