In android ScrollView there is no way or method to disable scrolling. but sometime if you want to disable scrolling of ScrollView while you are inside inner element, like if you want to disable ScrollView when you are inside Map view. So you can scroll Map view easily if you put Map view inside ScrollView. Because Map view has its own Scrolling feature which conflicts ScrollView’s scrolling and you are unable to scrolling map view. So at that time you think to disable Scrolling of ScrollView when you touch or make focus on Map view. But when you try to implement this then you get to know that there is no method to disable scrolling of ScrollView. You can disable the whole ScrollView but that is not a correct way to do this. So we can make our own ScrollView which having extra features are enable Scrolling or Disable scrolling. and we can do this using Inheritance feature of OOPS. So we will create a class which will Extend ScrollView class, which means our class will have all features derive from Base (ScrollView) class. ok so lets do this :
<ScrollViewandroid:layout_width="match_parent"android:id="@+id/scrollView"android:layout_height="match_parent"></ScrollView>
change this to (i will use my package name and Class name, change accoring to yours) :
<com.learnpainless.myscrollvoew.MyScrollViewandroid:layout_width="match_parent"android:id="@+id/scrollView"android:layout_height="match_parent"></com.learnpainless.myscrollvoew.MyScrollView>
Ok so now you have embedded your own ScrollView. to disable scrolling just call setScrolling() method to object of your ScrollView and pass value (true or false) where you want to disable. as shown in below example :
package com.learnpainless.myscrollvoew;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);MyScrollView scrollView = (MyScrollView) findViewById(R.id.scrollView);scrollView.setScrolling(false); // to disable scrollingscrollView.setScrolling(true); // to enable scrolling.}}
Quick Links
Legal Stuff
Social Media