How to detect whether the user is moving the button to top/or bottoom using onTouchListener

68 views Asked by At

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. But I don't now how to scroll the view manually. Can anyone help me to implement this feature.

UPDATED: I'm able to scroll the view. But the problem that I'm facing now is how to detect whether to scroll the view up or bottom on button click. Right now I'm using onTouchListner to scroll down.

@Override
    public boolean onTouch(View v, MotionEvent event) {

     if (v == mScrollBtn) {
            int scrollBarHeight = mScrollBar.getHeight();
            // if (event.getAction() == MotionEvent.ACTION_DOWN) {
            // int containerHeight = mFreeformContainer.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);
                mSignatureView.scrollTo(0, mScrollBtn.getHeight() +SCROLL_FACTOR* mTopMargin);
                // scrollDown();

}

Where

private int mTopMargin = 2;
    private static int SCROLL_FACTOR=2;
0

There are 0 answers