If you add the following line of code to an existing handler, your view will scroll to the right each time the button is clicked:
rightBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hsv.scrollTo((int)hsv.getScrollX() + 10, (int)hsv.getScrollY()); } });
If you want it to scroll more smoothly, you can use onTouchListener instead:
rightBtn.setOnTouchListener(new View.OnTouchListener() { private Handler mHandler; private long mInitialDelay = 300; private long mRepeatDelay = 100; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (mHandler != null) return true; mHandler = new Handler(); mHandler.postDelayed(mAction, mInitialDelay); break; case MotionEvent.ACTION_UP: if (mHandler == null) return true; mHandler.removeCallbacks(mAction); mHandler = null; break; } return false; } Runnable mAction = new Runnable() { @Override public void run() { hsv.scrollTo((int) hsv.getScrollX() + 10, (int) hsv.getScrollY()); mHandler.postDelayed(mAction, mRepeatDelay); } }; });
Change the delays you like to get the smoothness and responsiveness you want.
Catherine
source share