Ok, I figured it out myself.
First I had to extend the ScrollView class and add the OnScrollViewListener interface.
public class MyScrollView extends ScrollView { private OnScrollViewListener mListener; public MyScrollView(Context c, AttributeSet attrs) { super(c, attrs); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mListener != null) { mListener.onScrollChanged((OnScrollViewListener) this); } } public void setOnScrollViewListener(OnScrollViewListener listener) { mListener = listener; } public static interface OnScrollViewListener { public void onScrollChanged(OnScrollViewListener listener); } }
Later in my work, I inserted the mScrollDistance member, which indicates the number of pixels that the user scrolls.
public class ScrollActivity extends Activity { private int mScrollDistance; @Override protected void OnCreate(...) { ... final MyScrollView myScrollView = (MyScrollView) findViewById(R.id.scroll_view); myScrollView.setOnScrollViewListener(new MyScrollView.OnScrollViewListener() { public void onScrollChanged(OnScrollViewListener listener) { mScrollDistance = listener.getScrollY(); } }
Now mScrollDistance always gets a new value, and the drag location will be moved to the view location. I tested this and it works with layouts / views that are larger than the screen size.
Hope this helps.
source share