Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@cV2 Thank you so much for that code. It got me going in the direction I needed. Here's my modified version which stops scrolling at the edges of the image...</p> <pre><code> // set maximum scroll amount (based on center of image) int maxX = (int)((bitmapWidth / 2) - (screenWidth / 2)); int maxY = (int)((bitmapHeight / 2) - (screenHeight / 2)); // set scroll limits final int maxLeft = (maxX * -1); final int maxRight = maxX; final int maxTop = (maxY * -1); final int maxBottom = maxY; // set touchlistener ImageView_BitmapView.setOnTouchListener(new View.OnTouchListener() { float downX, downY; int totalX, totalY; int scrollByX, scrollByY; public boolean onTouch(View view, MotionEvent event) { float currentX, currentY; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: downX = event.getX(); downY = event.getY(); break; case MotionEvent.ACTION_MOVE: currentX = event.getX(); currentY = event.getY(); scrollByX = (int)(downX - currentX); scrollByY = (int)(downY - currentY); // scrolling to left side of image (pic moving to the right) if (currentX &gt; downX) { if (totalX == maxLeft) { scrollByX = 0; } if (totalX &gt; maxLeft) { totalX = totalX + scrollByX; } if (totalX &lt; maxLeft) { scrollByX = maxLeft - (totalX - scrollByX); totalX = maxLeft; } } // scrolling to right side of image (pic moving to the left) if (currentX &lt; downX) { if (totalX == maxRight) { scrollByX = 0; } if (totalX &lt; maxRight) { totalX = totalX + scrollByX; } if (totalX &gt; maxRight) { scrollByX = maxRight - (totalX - scrollByX); totalX = maxRight; } } // scrolling to top of image (pic moving to the bottom) if (currentY &gt; downY) { if (totalY == maxTop) { scrollByY = 0; } if (totalY &gt; maxTop) { totalY = totalY + scrollByY; } if (totalY &lt; maxTop) { scrollByY = maxTop - (totalY - scrollByY); totalY = maxTop; } } // scrolling to bottom of image (pic moving to the top) if (currentY &lt; downY) { if (totalY == maxBottom) { scrollByY = 0; } if (totalY &lt; maxBottom) { totalY = totalY + scrollByY; } if (totalY &gt; maxBottom) { scrollByY = maxBottom - (totalY - scrollByY); totalY = maxBottom; } } ImageView_BitmapView.scrollBy(scrollByX, scrollByY); downX = currentX; downY = currentY; break; } return true; } }); </code></pre> <p>I'm sure it could be refined a bit, but it works pretty well. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload