How to disable scrollView?

I already tried:

scrollView.setEnable(false); scrollView.setOnTouchListener(null); scrollView.requestDisallowInterceptTouchEvent(true); 

but none of them worked ... I don’t understand why, is there any other way to do this?

scrollView in xml:

 <ScrollView android:id="@+id/mainPage_scroll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:focusableInTouchMode="true" android:layout_below="@+id/tabBar" > </ScrollView> 
+4
source share
2 answers

For future reference, the much simpler solution that I am using for the drawing area within the ScrollView is to use requestDisallowInterceptTouchEvent to tell the parents and the chain not to interfere with the touches.

for example, in the drop-down view, where the parent in this case is LinearLayout inside the ScrollView , but can also be nested in other components:

 @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { this.parent.requestDisallowInterceptTouchEvent(true); // etc... } else if(event.getAction() == MotionEvent.ACTION_MOVE) { // etc... } else if (event.getAction() == MotionEvent.ACTION_UP) { this.parent.requestDisallowInterceptTouchEvent(false); // etc... } return true; } 
+4
source

There is no direct way to stop scrolling, but you can do it the other way. How:

 scrollview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return !enable; } }); 

when you set a valid variable to true, it will start scrolling, and when you set to false, stop scrolling.

+3
source

Source: https://habr.com/ru/post/1399360/


All Articles