0

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;
  • You don't want to use ScrollView just because the layout is small and wont fix the entire screen? You can use android:fillViewport="true" at the ScrollView so the layout will match the ScrollView. – Jonas452 Nov 14 '14 at 11:18
  • no the problem is that its a custom View & has touch events, so it doesn't take scroll events. And also I do not want it to scroll when I touch the screen. Only when I click on the scroll button, the view should be scrolled.Its a requirement – android beginer Nov 14 '14 at 11:30
  • http://stackoverflow.com/a/11269885/2382964 – Tushar Pandey Nov 14 '14 at 11:47
  • Accoring to the above link:it positions the view to a different location. I want to implement a scroll functionality – android beginer Nov 14 '14 at 12:39

0 Answers0