Rectangle 27 0

Disable Android scrollview, but still allow taps on buttons in the scroll view?


@Override
public boolean onTouchEvent(MotionEvent ev)
{
    App.log("onTouchEvent, with action : " + ev.getAction());
    switch(ev.getAction())
    {
        case MotionEvent.ACTION_MOVE:
            return false;
    }
    return super.onTouchEvent(ev);
}

In the end, I found the following solution did exactly what I needed:

Note
Rectangle 27 0

Disable Android scrollview, but still allow taps on buttons in the scroll view?


@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)
{
    final int dx;
    final int dy;

    if (isEnabled())
    {
        dx = deltaX;
        dy = deltaY;
    }
    else
    {
        dx = 0;
        dy = 0;
    }

    return super.overScrollBy(dx, dy, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
}

Hmmm... doesn't seem like the right answer, surely there's a way to stop the scrolling at the beginning without worrying about this 'overscroll' busines (and couldn't I just disable over-scrolling anyway with setOverScrollMode?)

ScrollView performs its scrolling using that method. Admittedly it's hardly a perfect solution, but without a specific allowScrolling(boolean) or similar on ScrollView's interface to perform what you want, I think it's as good as any other method.

You can override overscrollBy() and change the deltaX & deltaY values to 0 if disabled.

You'll probably also want to dynamically hide/show the scroll bar too on disabling/enabling.

Note
Rectangle 27 0

Disable Android scrollview, but still allow taps on buttons in the scroll view?


@Override
public boolean onTouchEvent(MotionEvent ev)
{
    App.log("onTouchEvent, with action : " + ev.getAction());
    switch(ev.getAction())
    {
        case MotionEvent.ACTION_MOVE:
            return false;
    }
    return super.onTouchEvent(ev);
}

In the end, I found the following solution did exactly what I needed:

Note