Skip to content

Commit 911025d

Browse files
authored
Merge pull request #5 from JarvisGG/issues2
fix-空白区域出发滑动,无法响应点击事件
2 parents eaa0492 + f9650a4 commit 911025d

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

.settings/org.eclipse.buildship.core.prefs

Lines changed: 0 additions & 2 deletions
This file was deleted.

library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,33 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
267267
}
268268
}
269269

270+
private boolean isTouchUnderChildView(MotionEvent event) {
271+
View targetChildView = getChildAt(0);
272+
float translationX = targetChildView.getTranslationX();
273+
float translationY = targetChildView.getTranslationY();
274+
float x = event.getX();
275+
float y = event.getY();
276+
return x >= targetChildView.getLeft() + translationX &&
277+
x <= targetChildView.getRight() + translationX &&
278+
y >= targetChildView.getTop() + translationY &&
279+
y <= targetChildView.getBottom() + translationY;
280+
}
281+
282+
/**
283+
* 不拦截 Touch 事件的几种情况
284+
* 1.不开启父亲布局拦截.
285+
* 2.当前子 View 为 null
286+
* 3.当前 Touch 事件没用作用到子 View
287+
* @param event
288+
* @return
289+
*/
270290
@Override
271291
public boolean onTouchEvent(MotionEvent event) {
272292
float velocityY = 0;
273-
if (getChildAt(0) == null || !isParentDispatchTouchEvent) {
293+
294+
if (!isParentDispatchTouchEvent ||
295+
getChildAt(0) == null ||
296+
!isTouchUnderChildView(event)) {
274297
return super.onTouchEvent(event);
275298
}
276299
if (isAnimating()) {

0 commit comments

Comments
 (0)