I have a custom view, which takes touch events.As a result, I cannot use scrollview. Since the page size is small, I want to scroll the view, using a custom scrollbar button.
I'm able to scroll the view. But the problem is that I do not know, how to detect whether the user is moving the finger up or down. Right now I'm using onTouchListner to scroll down the view.
How to detect in which direction users finger is pointed? Here is my code:
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v == mScrollBtn) {
int scrollBarHeight = mScrollBar.getHeight();;
LayoutParams params = (LayoutParams) mScrollBtn.getLayoutParams();
params.topMargin = SCROLL_FACTOR*mTopMargin;
mTopMargin = mTopMargin + 1;
if (params.topMargin <= mScrollBar.getHeight()-mBottomPadding) {
mScrollBtn.setLayoutParams(params);
// scrollDown(View.FOCUS_DOWN);
mCustomView.scrollTo(0, mScrollBtn.getHeight() +SCROLL_FACTOR* mTopMargin);
}
Where SCROLL_FACTOR=2 & mTopMargin=2.
Thanks in Advance
You can calculate the direction by simply moritoring the onMove values.