From d9bad5e29132ba9903522c72aab80c1f19367f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=B6=E4=BC=9F?= Date: Mon, 28 Jun 2021 11:03:19 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9D=9E=E5=B8=B8=E5=B0=91=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E7=9A=84=E6=BB=91=E5=8A=A8=E5=8D=A1=E9=A1=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 作者之前给滑动到边界时做了减速的效果,但是在数据只有两三条的时候,这个减速效果就变成了卡顿。参考androidWheelView的实现,修改了实现方案,在数据只有两三条的时候,不会出现卡顿。 --- .../java/com/contrarywind/view/WheelView.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/wheelview/src/main/java/com/contrarywind/view/WheelView.java b/wheelview/src/main/java/com/contrarywind/view/WheelView.java index ea7327c7..38df75bc 100644 --- a/wheelview/src/main/java/com/contrarywind/view/WheelView.java +++ b/wheelview/src/main/java/com/contrarywind/view/WheelView.java @@ -670,11 +670,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override public boolean onTouchEvent(MotionEvent event) { boolean eventConsumed = gestureDetector.onTouchEvent(event); - boolean isIgnore = false;//超过边界滑动时,不再绘制UI。 - float top = -initPosition * itemHeight; float bottom = (adapter.getItemsCount() - 1 - initPosition) * itemHeight; - float ratio = 0.25f; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: @@ -690,13 +687,10 @@ public boolean onTouchEvent(MotionEvent event) { // normal mode。 if (!isLoop) { - if ((totalScrollY - itemHeight * ratio < top && dy < 0) - || (totalScrollY + itemHeight * ratio > bottom && dy > 0)) { - //快滑动到边界了,设置已滑动到边界的标志 - totalScrollY -= dy; - isIgnore = true; - } else { - isIgnore = false; + if (totalScrollY < top) { + totalScrollY = (int) top; + } else if (totalScrollY > bottom) { + totalScrollY = (int) bottom; } } break; @@ -735,7 +729,7 @@ public boolean onTouchEvent(MotionEvent event) { } break; } - if (!isIgnore && event.getAction() != MotionEvent.ACTION_DOWN) { + if (event.getAction() != MotionEvent.ACTION_DOWN) { invalidate(); } return true;