My ultimate goal is to stop the scroll in specific locations, so the objects being viewed are shown completely, and the solution I came up with is by checking the scrollX location of the view when the touch is released. I did have a momentum issue, as the scroll could still continue due to the scroll velocity also after catching the touch event, I solved that using MotionEvent.ACTION_CANCEL, which I am not happy with, as the scrollTo is optically pleasing, but the MotionEvent.ACTION_CANCEL kills its effect.
My question is, is there a more elegant way to do this? Ideal would be if I could simply instruct my ScrollView NOT to have momentum/velocity.
myView.setOnTouchListener(new HorizontalScrollView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
event.setAction(MotionEvent.ACTION_CANCEL);
int x = myView.getScrollX();
if (x < 150)
myView.scrollTo(0,0);
else if (x<450)
myView.scrollTo(300,0);
else
myView.scrollTo(600,0);
}
return false;
}
});