This should be pretty straightforward but it seems that I missed something --- how do you figure out the direction (left/right/up/down) of a scrolling event for a ScrollView
Research is telling me that there is no scroll listener for that case.
You could try your approch.
Another thing I would try is to override onScrollChanged (which provides the scroll position before) and so creating your own ScrollView
Update:
This one workes for me. It scrolls to the right but not to the left.
public class CustomScrollView extends HorizontalScrollView {
public CustomScrollView(Context context) {
super(context);
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onScrollChanged(int w, int h, int ow, int oh) {
if (w < ow) {
scrollTo(ow, h);
}
}
}
use this
scrollView.setOnTouchListener(new View.OnTouchListener() {
float y1 = 0;
float y0 = 0;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
y0 = motionEvent.getY();
Log.i("Y", motionEvent.getAction() + " + " + (y0 - y1));
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
y1 = motionEvent.getY();
if (y0 - y1 > 0) {
Log.i("Y", motionEvent.getAction() + " + " + (y0 - y1));
} else if (y0 - y1 < 0) {
Log.e("Y", motionEvent.getAction() + " - " + (y0 - y1));
}
}
return false;
}
});