Skip to content

Commit 85d0f4b

Browse files
committed
修复滑动冲突问题
1 parent bbba992 commit 85d0f4b

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## 添加依赖
88
```compile
9-
compile 'com.cncoderx.wheelview:library:1.2.6'
9+
compile 'com.cncoderx.wheelview:library:1.2.7'
1010
```
1111
## 使用方法
1212
#### 在xml文件中添加

library/src/main/java/com/cncoderx/wheelview/WheelScroller.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public void computeScroll() {
3939

4040
private int currentIndex = -1;
4141

42-
private void doScroll(int distance) {
42+
private boolean doScroll(int distance) {
43+
int scrollOffset = mScrollOffset;
4344
mScrollOffset += distance;
4445
if (!mWheelView.isCyclic()) {
4546
// 限制滚动边界
@@ -50,7 +51,11 @@ private void doScroll(int distance) {
5051
mScrollOffset = maxOffset;
5152
}
5253
}
53-
notifyWheelChangedListener();
54+
if (mScrollOffset != scrollOffset) {
55+
notifyWheelChangedListener();
56+
return true;
57+
}
58+
return false;
5459
}
5560

5661
void notifyWheelChangedListener() {
@@ -91,8 +96,9 @@ public void setCurrentIndex(int index, boolean animated) {
9196
startScroll(0, mScrollOffset, 0, distance, JUSTIFY_DURATION);
9297
mWheelView.invalidate();
9398
} else {
94-
doScroll(distance);
95-
mWheelView.invalidate();
99+
if (doScroll(distance)) {
100+
mWheelView.invalidate();
101+
}
96102
}
97103
}
98104

@@ -147,13 +153,17 @@ public boolean onTouchEvent(MotionEvent event) {
147153
case MotionEvent.ACTION_DOWN:
148154
lastTouchY = event.getY();
149155
forceFinished(true);
156+
mWheelView.getParent().requestDisallowInterceptTouchEvent(true);
150157
break;
151158
case MotionEvent.ACTION_MOVE:
152159
float touchY = event.getY();
153160
int deltaY = (int) (touchY - lastTouchY);
154161
if (deltaY != 0) {
155-
doScroll(-deltaY);
156-
mWheelView.invalidate();
162+
if (doScroll(-deltaY)) {
163+
mWheelView.invalidate();
164+
} else {
165+
mWheelView.getParent().requestDisallowInterceptTouchEvent(false);
166+
}
157167
}
158168
lastTouchY = touchY;
159169
break;

0 commit comments

Comments
 (0)