Search code examples
androidkotlinscrollviewgesture

Make layout unscrollable when GestureOverlayView is touched


In FragmentA, I have a scrollable layout. Inside the layout, I have GestureOverlayView.

<android.gesture.GestureOverlayView
                android:id="@+id/signGesture"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@android:color/white"
                android:fadeEnabled="false"
                android:fadeOffset="10000"
                android:gestureColor="@color/black"
                android:gestureStrokeLengthThreshold="0.1"
                android:gestureStrokeType="multiple"
                android:orientation="vertical">

Is there a way to make the layout unscrollable when GestureOverlayView is touched ? I can't draw anything because the layout is moving !

enter image description here


Solution

  • You should use OnGesturePerformedListener on your gesture view and there you disable your scrollView scrolling by returning true on the touch listener

    gesture.addOnGesturePerformedListener(new OnGesturePerformedListener() {
    
        public void onGesturePerformed(GestureOverlayView v, Gesture g) {
    
            mScrollView.setOnTouchListener( new OnTouchListener() {
    
              @Override
              public boolean onTouch(View v, MotionEvent event) 
              {
                    return true;
              }
            });
        }
    
    });
    

    EDIT

    You can take a look at this answer , it actually present a custom ScrollView that will intercept the scroll touch and disable it when you perform gesture listener.