Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a solution to this problem, if not the cause of the problem.</p> <p>Replacing the line <code>canvas.setMatrix(matrix);</code> with <code>canvas.concat(matrix);</code> did the trick. I think it partly had to do with the fact that setting the matrix changes the origin of the canvas to be calculated with respect to the screen height and width rather than the view's. But there are mysteries because this also magically solved some other problems I had.</p> <p><strong>EDIT</strong></p> <p>It turns out that one of the consequences of doing things this way is that <code>event.getX()</code> and <code>event.getY()</code> in the <code>onTouchEvent(MotionEvent event)</code> method start returning integers which are hard to deal with. My custom view is for making a zoomable, pannable grid of squares which I can click on and get the coordinate of the square. Using this method I try to get the (x,y) coordinate of a click event (<code>MotionEvent.ACTION_UP</code> case in <code>onTouchEvent</code> method). </p> <p>I try to get the x coordinate, for instance, via</p> <pre><code>int x = (int) ((start.x - dspl.x)/(cellWidth*scaleFactor)); </code></pre> <p>I account for how much I have panned the screen (<code>dspl</code> gives the total displacement that has occurred thus far) and the amount I have zoomed it (<code>scaleFactor</code> gives the total scaling that has occurred). But this does not account for the points about which successive zooms have occurred. </p> <p>Any good ideas about how to get the right coordinates?</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