ZoomLayout과 NodeView 간의 터치 이벤트 처리 문제가 발생하였다

ZoomLayout은 확대/축소, 드래그 기능이 있고 NodeView는 노드를 이동 시키는 이벤트를 발생되도록 시도하였지만 ZoomLayout에서 드래그 기능만 정상 작동되었다. ZoomLayout과 NodeView 간의 이벤트 처리 충돌로 인해 발생한 문제였다

onInterceptTouchEvent 터치 이벤트 관리

참고자료: https://developer.android.com/develop/ui/views/touch-and-input/gestures/viewgroup

override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        if (mindMapContainer.selectNode == null) {
            return false
        }
        return super.onInterceptTouchEvent(ev)
    }

ZoomLayout에서 onInterceptTouchEvent 메서드를 활성화 시켜 ZoomLayout에서 발생하는 터치 이벤트를 NodeView가 가로챌 수 있도록 했다 이 메서드를 통해 터치 이벤트가 자식 뷰로 전달되기 전에 부모 뷰에 의해 먼저 처리하도록 하였다

따라서 선택한 노드가 null이 아닐 때만 NodeView가 이벤트를 가로채도록 설정했다. 이는 불필요한 이벤트를 가로채는 것을 방지하도록 하였고, 필요한 경우에만 NodeView가 터치 이벤트를 처리할 수 있도록 하였다

onInterceptTouchEvent를 활성화함으로써 ZoomLayout과 NodeView 사이에서 터치 이벤트가 효과적으로 조정하여 노드를 자유롭게 이동시킬 수 있게 되었고 동시에 ZoomLayout의 드래그 기능도 영향을 받지 않게 되었다

터치이벤트.png

Dec-06-2023 15-47-31.gif

Dec-06-2023 15-51-44.gif