I am trying to get the canvas coordinates for the android application that I am creating. It works fine until I add code to use the focus point (the following two lines):
scalePoint.setX((int) detector.getFocusX()); scalePoint.setY((int) detector.getFocusY());
Here is my source code for my view class:
package us.kniffin.Jigsaw; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; public class TestView extends View { private float mLastTouchX; private float mLastTouchY; private float mPosX; private float mPosY; private Rect rect; private float cX, cY;
Any ideas what I need to do to get this to work?
Update: I replaced the sample code with another that has the same problem but is simplified to the basic requirements
Update again: The problem occurs after scaling. The coordinates are correct before scaling, but after that the coordinates are too far to the right and below where you click. It seems that the more you zoom out, the more errors they get.
source share