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);
}
}
"작동하지 않음"의 의미를 명확히 할 수 있습니까? 부모'ViewGroup'이 여전히이 이벤트를 가로 채고 있음을 의미합니까? – azizbekian
예, 수평 스크롤은 여전히 일종의 (그러나 완만하지만) 수직 스크롤은 전혀하지 않습니다. –