Skip to content

Commit 77d0239

Browse files
committed
修复bug
1 parent be776bd commit 77d0239

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

app/src/main/java/com/donkingliang/consecutivescrollerdemo/SinkStickyActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
3939
scrollerLayout.setOnVerticalScrollChangeListener(new ConsecutiveScrollerLayout.OnScrollChangeListener() {
4040
@Override
4141
public void onScrollChange(View v, int scrollY, int oldScrollY, int scrollState) {
42-
if (scrollY > flSink.getHeight()){
42+
if (scrollY > flSink.getHeight() || scrollY < 0){
4343
scrollerLayout.setStickyOffset(0); // 恢复吸顶偏移量
4444
} else {
4545
// 通过设置吸顶便宜量,实现flSink滑动隐藏时的向上移动效果

consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/ConsecutiveScrollerLayout.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ public float getInterpolation(float t) {
283283
*/
284284
private boolean isTouchNotTriggerScrollStick = false;
285285

286+
/**
287+
* 判断手指触摸的view是否需要拦截事件
288+
*/
289+
private boolean isIntercept = false;
290+
286291
/**
287292
* 在快速滑动的过程中,触摸停止滑动
288293
*/
@@ -647,6 +652,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
647652

648653
mDownLocation[0] = ScrollUtils.getRawX(this, ev, actionIndex);
649654
mDownLocation[1] = ScrollUtils.getRawY(this, ev, actionIndex);
655+
isIntercept = isIntercept(mDownLocation[0], mDownLocation[1]);
650656
isTouchNotTriggerScrollStick = ScrollUtils.isTouchNotTriggerScrollStick(this, mDownLocation[0], mDownLocation[1]);
651657
break;
652658
case MotionEvent.ACTION_POINTER_DOWN:
@@ -658,6 +664,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
658664
requestDisallowInterceptTouchEvent(false);
659665
mDownLocation[0] = ScrollUtils.getRawX(this, ev, actionIndex);
660666
mDownLocation[1] = ScrollUtils.getRawY(this, ev, actionIndex);
667+
isIntercept = isIntercept(mDownLocation[0], mDownLocation[1]);
661668
isTouchNotTriggerScrollStick = ScrollUtils.isTouchNotTriggerScrollStick(this, mDownLocation[0], mDownLocation[1]);
662669

663670
initAdjustVelocityTrackerIfNotExists();
@@ -677,7 +684,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
677684
int offsetY = (int) ev.getY(pointerIndex) - mEventY;
678685
int offsetX = (int) ev.getX(pointerIndex) - mEventX;
679686
if (SCROLL_ORIENTATION == SCROLL_NONE
680-
&& (isIntercept(ev) || isIntercept(mDownLocation[0], mDownLocation[1]))) {
687+
&& (isIntercept || isIntercept(ev))) {
681688
if (disableChildHorizontalScroll) {
682689
if (Math.abs(offsetY) >= mTouchSlop) {
683690
SCROLL_ORIENTATION = SCROLL_VERTICAL;
@@ -723,6 +730,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
723730
mEventX = (int) ev.getX(newPointerIndex);
724731
mDownLocation[0] = ScrollUtils.getRawX(this, ev, newPointerIndex);
725732
mDownLocation[1] = ScrollUtils.getRawY(this, ev, newPointerIndex);
733+
isIntercept = isIntercept(mDownLocation[0], mDownLocation[1]);
726734
isTouchNotTriggerScrollStick = ScrollUtils.isTouchNotTriggerScrollStick(this, mDownLocation[0], mDownLocation[1]);
727735
}
728736
initAdjustVelocityTrackerIfNotExists();
@@ -767,6 +775,7 @@ && isIntercept(ev) && Math.abs(yVelocity) >= mMinimumVelocity) {
767775
mDownLocation[0] = 0;
768776
mDownLocation[1] = 0;
769777
isTouchNotTriggerScrollStick = false;
778+
isIntercept = false;
770779
overSpinner();
771780
break;
772781
}
@@ -803,7 +812,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
803812

804813
// 需要拦截事件
805814
if (SCROLL_ORIENTATION != SCROLL_HORIZONTAL
806-
&& (isIntercept(ev) || isIntercept(mDownLocation[0], mDownLocation[1]))) {
815+
&& (isIntercept || isIntercept(ev))) {
807816
return true;
808817
}
809818
break;

0 commit comments

Comments
 (0)