Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well If I understand correctly according to your code you are using a <code>SurfaceView</code> so to draw inside it you can read the accepted answer <a href="https://stackoverflow.com/questions/6690898/drawing-to-a-surfaceview-in-android" title="here">here</a> where inside <code>private void drawMyStuff(final Canvas canvas)</code> you have to put the code to draw the rectangles you want, and call <code>invalidate()</code> to redraw the <code>SurfaceView</code> every time you change something (like the coordinates).</p> <p>Also you can create your own custom <code>View</code> and draw inside it, you can see a working example I am using in my project <a href="https://github.com/dragondgold/MultiWork/tree/master/src/com/roboticarm/andres" rel="nofollow noreferrer" title="here">here</a>.</p> <p>You already have the (x,y) coordinates of the touch so to draw the rectangles inside your <code>SurfaceView</code> using <code>Canvas</code>. Here some code you can use for reference, all you have to do is change the numbers by the (x,y) coordinates where you want to draw:</p> <pre><code>Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); canvas.drawRect(30, 30, 80, 80, paint); paint.setStrokeWidth(0); paint.setColor(Color.CYAN); canvas.drawRect(33, 60, 77, 77, paint ); paint.setColor(Color.YELLOW); canvas.drawRect(33, 33, 77, 60, paint ); </code></pre> <p>Now to resize your rectangle you will have to save the coordinates somewhere, you can use <a href="http://developer.android.com/reference/android/graphics/Rect.html" rel="nofollow noreferrer" title="Rect">Rect</a> to save the coordinates for each rectangle you have. Then to re-size them you can read the coordinates from the touchscreen and see if they are NEAR some of your rectangles coordinates. I say near because it would be difficult to touch exactly the coordinate of the corner, you have to see if it is for example in +-10 pixels around the corner. Take care of the rectangle size maybe those 10 pixels are the rectangle width or height. </p> <p>Finally on <code>ACTION_DOWN</code> you track the corner as I write before and on <code>ACTION_UP</code> you take the new coordinates of the corner you detected before on <code>ACTION_DOWN</code>, then, you call <code>invalidate()</code> to redraw your rectangles and you are done!</p> <p>I hope you understood me and helps you in some way :)</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