I am working on my first "real" Android application, a graphical workflow editor. The drawing is executed in a custom class, which is a subclass of View. At the moment when my elements are rectangles that are drawn on the canvas. To detect actions on elements, I compare the coordinates and check the elements at the point of contact.
To implement the zoom gesture, I tried http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
Using the canvas.scale (...) function with 4 arguments, centered scaling works well, but I lose the ability to calculate the coordinates of the canvas using the offset from mPosX and mPosY to determine if the item has a touch after scaling.
I tried changing the example in the blogpost above to center the canvas on the zoom gesture with:
canvas.save(); canvas.translate(mPosX, mPosY); canvas.scale(mScaleFactor, mScaleFactor, mScalePivotX, mScalePivotY);
I did not find examples of how this could be done without losing the offset of the link to calculate the coordinates. Is there an easy way? I tried to calculate the offset with the center of gestures and the zoom factor, but failed: /
I have seen that other examples that use ImageView often use Matrix to transform the image. Can this be done with a custom view and canvas? If so, how can I get the x and y offset to check the coordinates?
Also, if my ideas are completely wrong, I would be very happy to see some examples of how this is done correctly.
thanks!;)
android view zoom
m4tt
source share