I have a LinearLayout inside a HorizontalScrollView. The content is just a image. While scrolling, I need to achieve the same behavior you get when setting the paging option
i found another way to get the same effect and i think is more readable. Here is the way:
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP)
{
float currentPosition = hsv.getScrollX();
float pagesCount = hsv.getChildCount();
float pageLengthInPx = hsv.getMeasuredWidth()/pagesCount;
int page = (int) (Math.floor((currentPosition - pageLengthInPx / 2) / pageLengthInPx) + 1);
hsv.scrollTo((int) (page * pageLengthInPx), 0);
}
return false;
}