Skip to content

Commit

Permalink
Merge pull request #5 from JarvisGG/issues2
Browse files Browse the repository at this point in the history
fix-空白区域出发滑动,无法响应点击事件
  • Loading branch information
JarvisGG authored Jan 18, 2019
2 parents eaa0492 + f9650a4 commit 911025d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .settings/org.eclipse.buildship.core.prefs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,33 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}
}

private boolean isTouchUnderChildView(MotionEvent event) {
View targetChildView = getChildAt(0);
float translationX = targetChildView.getTranslationX();
float translationY = targetChildView.getTranslationY();
float x = event.getX();
float y = event.getY();
return x >= targetChildView.getLeft() + translationX &&
x <= targetChildView.getRight() + translationX &&
y >= targetChildView.getTop() + translationY &&
y <= targetChildView.getBottom() + translationY;
}

/**
* 不拦截 Touch 事件的几种情况
* 1.不开启父亲布局拦截.
* 2.当前子 View 为 null
* 3.当前 Touch 事件没用作用到子 View
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
float velocityY = 0;
if (getChildAt(0) == null || !isParentDispatchTouchEvent) {

if (!isParentDispatchTouchEvent ||
getChildAt(0) == null ||
!isTouchUnderChildView(event)) {
return super.onTouchEvent(event);
}
if (isAnimating()) {
Expand Down

0 comments on commit 911025d

Please sign in to comment.