Tuesday, April 7, 2015

requestDisallowInterceptTouchEvent in android




The onInterceptTouchEvent() method is called whenever a touch event is detected on the surface of a ViewGroup,
including on the surface of its children. If onInterceptTouchEvent() returns true, the MotionEvent is intercepted,
meaning it will be not be passed on to the child, but rather to the onTouchEvent() method of the parent.


onInterceptTouchEvetn 순서
부모 -> 자식


onInterceptTouchEvent 이거는 자신 또는 자식의 터치가 발견되었을때 호출된다.
onInterceptTouchEvent true = 지금 위치에 스크롤을 사용하겠다.
                            false = 하위의 스크롤을 사용하겠다.





public abstract void (boolean disallowIntercept)

Added in API level 1
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

This parent should pass this call onto its parents.
This parent must obey this request for the duration of the touch
(that is, only clear the flag after this parent has received an up or a cancel.

disallowIntercept True if the child does not want the parent to intercept touch events.

requestDisallowInterceptTouchEvent true : 상위 부모가 이벤트를 가져가지 못하게 한다.


ex)
mBannerPager.setOnTouchListener(new OnTouchListener() {
                              @Override
                              public boolean onTouch(View v, MotionEvent event) {
                                     
                                      switch (event.getActionMasked()) {
                                      case MotionEvent.ACTION_DOWN:
                                             mPager.requestDisallowInterceptTouchEvent(true);
                                             break;
                                      default:
                                             break;
                                      }
                                      return false;
                              }
                       });

No comments:

Post a Comment