title: How do I program a Scrollable SurfaceView in Android Java?
body: <p>I am trying to draw an image that is larger than the screen, and let the user scroll around it. The image is some graphs that are calculated by my code from some data. (This is in Android using Java).</p>
  
  <p>What I want is a View (actually a SurfaceView) that can be scrolled by the user. I have tried putting a SurfaceView inside a ScrollView but the whole image drawn by the SurfaceView is very large and so (a) there are performance issues as my app is drawing the whole SurfaceView when it should only need to do the part that is in the viewport and (b) my app crashes with "dimensions too large... out of memory" errors.</p>
  
  <p>It would be best for me if the View could implement scrolling (vertical only) and then pass the y-value to my code so it could draw the visible part of my image in the viewport.</p>
  
  <p>Alternatively I could capture the 'mouse' events and calculate the y-value myself.</p>
  
  <p>Does anyone have any code so that I can do this?</p>
  
  <p>Update: I should clarify, the image is drawn by my program code using Canvas.drawLine() and the like. I can calculate which parts of the image fit within my viewport, provided I have the state of the scroll as a y-value, and I can calculate the absolute y-coordinate of each point by subtracting scroll y-value. What I need is something that works to find when the user scrolls the image and what the resulting y-value is. A scrollbar would also be nice.</p>
  
  <p>Update: I am using SurfaceView so that I can update the image from another Thread and so improve user interface performance.</p>