The problem with most of the answers here is that they only achieve vertical or horizontal scroll, BUT not diagonal (horizontal AND vertical at the same time).
The easiest way I've found to get it working is:
- Create two new classes extending
HorizontalScrollView and ScrollView (use whatever name, like "ScrollViewX" and "ScrollViewY").
- Make a new XML and use the class extending
HorizontalScrollView inside the one extending ScrollView.
- Inside the two classes, override their
onTouch methods to always return false (override and use performClick() too, for accessibility reasons).
- Use a
GestureDetector and update the scrolling of both classes with it.
Creating the classes isn't really required, since you could just set an onTouch listener for both. But I believe it's better in terms of organization and it may be useful if you require more customizations later.
The only problem I've found is that, since one ScrollView is inside the other, now one of the scrollbars is only going to be visible when you scroll while being on the edge of the view.
A workaround could be: either don't use scrollbars, or make a custom view to replace said scrollbar (you set its size according to the ScrollView size and move it as the scroll is updated).
Note: I tried to describe it as much as I could. If someone needs more details, let me know