Moving drawing in canvas android -
I am trying to transfer the drawing to the canvas. I have a working code but the problem is that when I click on the canvas to pull the second time, it resets it to its initial position (its default position) and then starts again. I left it on my first pull, from where I want to move forward.
In the code of my custom view, I have a function called setupCoordinates, where the coordinates of my pictures begin. (X and y, I am using it to move the image. These values are updated by the touch listener of my activity)
I am adding my thoughts as a relative layout < / P>
relLay.addView (custView); There is a touch listener in my layout
relLay.setOntouchListener (touch); And in my touch listener I get evet.getX () and event.getY ()
custView.setXY (evet. GetX), event. GetY ()); Below is the code of my custom view where I am drawing:
Public made views (reference context) {super (reference); SetupDrawing (); SetupCoordinates (); } Private zero setup drying () {path = new path (); Paint = new paint (); Borderpaint = new paint (); Paint.setColor (color); Paint.setAntiAlias (right); Paint.setStyle (Paint.Style.FILL); BorderPaint.setColor (Color.BLACK); BorderPaint.setAntiAlias (true); BorderPaint.setStyle (Paint.Style.STROKE); } Personal Zero Setup Coordination () {x = 0; Y = 0; Top = 150; Correct = 450; Left = 200; Bottom = 400; Line x = 120; Linea = 300; OpenSize = 20; } @ Override Scared Protected Zero (Canvas Canvas) {Super. Don (canvas); Path.reset (); MCanvas = canvas; Rectf = new RectF (left + x, top + y, right + x, bottom + y); Rect = rectf; Int angle = (int) angle (new point (getWidth ()) / 2, (getHeight ()) / 2), new point (linex, liney); Int startAngle = angle + (openSize / 2); Int Sweepnangle = 360 - Open Size; Path.arcTo (rectf, startAngle, sweepAngle); Path.lineTo (linex, liney); Canvas skeleton (path, paint); Canvas davarapath (path, boundary picture); } Public Zero setXY (int dx, int dy) {x = dx; Y = dy; Invalid (); } Private double angles (point point 1, pointpoint 2) {double deltax = (point 1.x - point 2.x); Double delta = (dot 1.y - point2.y); Double angle = monastery.degraz (Math. Tata 2 (Delta, Deltax)); If (angle <0) {angle = = 360; } If (angle> 360) {angle - = 360; } // 0 compensation for angles - = 180; Return angle; } Can anyone tell me that when I pull it the second time, then why is it being reset in its initial state? I am also open for other ways to move pictures inside the canvas, if any, please tell me
Here's a sample how to avoid snapping, so the values should work:
< Code> switch (event.getAction ()) {case MotionEvent.ACTION_DOWN: mCustomView.setXYAnimated ((int) event.getX (), (int) event.getY ()); break; Case Motion Event Action_ MOVE: mCustomView.setXY ((int) event.getX (), (int) event.getY ()); break; Case MotionEvent.ACTION_UP: mCustomView.setXY ((int) event.getX (), (int) event.getY ()); break; } In custom view:
Private int X = -1; Private int y = -1; Private countdown timer mCountDownTimer; Public Zero setXY (int dx, int dy) {if (mCountDownTimer == zero) {x = dx; Y = dy; Invalid (); }} Public ZeroSet XVAnited (last integer new, last integer new) {if (x == -1 & amp; y == -1) {setXY (newX, newY); } And {if (mCountDownTimer == tap) {last int time = 250; MCountDownTimer = New County Downtime (Time, 10) {@ Override Public Recognition on Tech (Long Million Unfinancial) {Float Progress = 1 - ((Float) Mill Available / Time); Int x2, y2; If (x and lieutenant; new x) {x2 = (int) (x + (progression * (newX - x))} and {x2 = (int) (x - (progression * (x - newX)); } If (Y & L; new) {y2 = (int (y + (progression * (new y - y)))} and {y2 = (int) (y - (progression * (y - newY)) };} X = x2; y = y2; postInvalidate ();} @ Override Finnish () {mCountDownTimer = null; setexway (NewX, NewYew);}}. Start ();}}}
Comments
Post a Comment