Create custom ScrollView to enable or disable scrolling Android

Fetching Comments ...

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 :

  • create a new class and name it what you want, i will name it as MyScrollView. and extend ScrollView class.
  • Now you need to create constructor of your class, Android studio will give you 4 type of Constructor. extend all of them. because in future we can use that constructors.
  • override 2 methods of ScrollView “onInterceptTouchEvent” and “onTouchEvent”.
  • create a boolean variable which will check that scrolling is enabled or disabled. by default set its value to true.
  • now create boolean type method and return that variable which you have just created.
  • Now create a void method to enable and disable scrolling which requires a parameter of boolean type. i will name this method as setScrolling(boolean enable) as shown below :

So how to use this custom ScrollView class ?

  • Goto your xml file where you want to use ScrollView. if you already have ScrollView inside your xml then replace that ScrollView tag with your custom ScrollView’s class name and package name.


for example :

change this to (i will use my package name and Class name, change accoring to yours) :



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.os.Bundle;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        MyScrollView scrollView = (MyScrollView) findViewById(;

        scrollView.setScrolling(false); // to disable scrolling

        scrollView.setScrolling(true); // to enable scrolling.

Share This:

LearnPainLess On Instagram

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.