File tree Expand file tree Collapse file tree
library/src/main/java/jarvis/com/library Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff 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 ()) {
You can’t perform that action at this time.
0 commit comments