2017-04-25 1 views
1

RecyclerView 내부에 MapView를 스크롤하려고하므로 TouchEvent 전후에 requestDisallowInterceptTouchEvent()을 설정하고 있습니다.Scrollable MapView RecyclerView 내부 : dispatchTouchEvent vs onTouchEvent

이상한 점은 dispatchTouchEvent() 메서드에서 설정하면 작동하지만, onTouchEvent() 메서드에서 동일하게 작동하면 작동하지 않습니다.

누군가 내가 이것을 설정할 수없는 이유를 설명 할 수 있습니까 onTouchEvent()?

작업 :

public class WorkingScrollableListItemMapView extends MapView { 

    // constructors 

    @Override 
    public boolean dispatchTouchEvent(MotionEvent ev) { 
     switch (ev.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       // Stop parents from handling the touch 
       this.getParent().requestDisallowInterceptTouchEvent(true); 
      break; 
      case MotionEvent.ACTION_UP: 
       // Allow parents from handling the touch 
       this.getParent().requestDisallowInterceptTouchEvent(false); 
       break; 
     } 
     return super.dispatchTouchEvent(ev); 
    } 
} 

작동하지 : 이벤트를 처리하기위한

public class NotWorkingScrollableListItemMapView extends MapView { 

    // constructors 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     switch (ev.getAction()) { 
      case MotionEvent.ACTION_UP: 
       // Allow parents from handling the touch 
       this.getParent().requestDisallowInterceptTouchEvent(false); 
       break; 
      case MotionEvent.ACTION_DOWN: 
       // Stop parents from handling the touch 
       this.getParent().requestDisallowInterceptTouchEvent(true); 
       break; 
     } 
     return super.onTouchEvent(ev); 
    } 
} 
+0

"작동하지 않음"의 의미를 명확히 할 수 있습니까? 부모'ViewGroup'이 여전히이 이벤트를 가로 채고 있음을 의미합니까? – azizbekian

+0

예, 수평 스크롤은 여전히 ​​일종의 (그러나 완만하지만) 수직 스크롤은 전혀하지 않습니다. –

답변

1

호출 순서는 순서로 다소 있습니다 onInterceptTouchEvent, onDispatchTouchEvent, dispatchTouchEvent, onTouchEvent. 저에게, onTouchEvent는 이벤트 처리의 마지막 단계임을 나타냅니다. 아주 마지막 단계에서 이벤트를 처리하는 사람 &을 조작하는 것은 너무 늦었을 것입니다. 이전에 이벤트를 처리하는 방법을 살펴보면 소스 코드는 무엇이라고 말합니까?

+0

실제로 onTouchEvent가 마지막에 호출됩니다. 그러나 dispatchTouchEvent() 메서드는 dispatchMethod()의 시작 부분에서 onTouchEvent()를 호출하므로 이벤트가 손실됩니다. 하지만 왜 그런지 이해하지 못합니다 ... –