Create a CustomScrollView class that extends ScrollView.
With this we can change the scrolling enabled property of the Scrollview.
public class CustomScrollView extends ScrollView {
boolean bScrollable = false;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollingEnabled(boolean enabled) {
bScrollable = enabled;
}
public boolean isScrollable() {
return bScrollable;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (bScrollable) {
return super.onTouchEvent(ev);
}
// only continue to handle the touch event if scrolling enabled
return bScrollable; // mScrollable is always false at this point
default:
return super.onTouchEvent(ev);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Don't do anything with intercepted touch events if
// we are not scrollable
if (!bScrollable) {
return false;
} else {
return super.onInterceptTouchEvent(ev);
}
}
}