title: Android: Getting touch location point on ImageView
body: <p>I am making an app wherein I want to get the touched point on Image. I have tried using this link :</p>
  
  <p><a href="https://stackoverflow.com/questions/6038867/android-how-to-detect-touch-location-on-imageview-if-the-image-view-is-scaled-b">Android: how to detect touch location on ImageView if the image view is scaled by matrix?</a></p>
  
  <p>But, I am not able to get correct touched points.</p>
  
  <p>What I am doing wrong? </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public boolean onTouch(View v, MotionEvent event) {
                  v.onTouchEvent(event);
  
  
  
  
                  matrix.getValues(m);
                  float x = m[Matrix.MTRANS_X];
                  float y = m[Matrix.MTRANS_Y];
                  PointF curr = new PointF(event.getX(), event.getY());
  
                  switch (event.getAction()) {
                  case MotionEvent.ACTION_DOWN:
                      last.set(event.getX(), event.getY());
                      EventX=event.getX();
                      EventY=event.getY();
                      Log.d("ImageX"+event.getX(), "ImageY"+event.getY());
                      start.set(last);
                      mode = DRAG;
                      PosterActivity.isTouched=false;
  
                      break;
                  case MotionEvent.ACTION_MOVE:
                      // Log.i("onTouch", "origWidth : " + origWidth +
                      // " origHeight : " + origHeight);
                      if (mode == DRAG) {
                          deltaX= curr.x - last.x;
                          Log.d("deltaX",""+deltaX);
  
                          deltaY = curr.y - last.y;
                          Log.d("deltay",""+deltaY);
                          scaleWidth = Math.round(origWidth * saveScale);
                          scaleHeight = Math.round(origHeight * saveScale);
                          if (scaleWidth &lt; width) {
                              deltaX = 0;
                              if (y + deltaY &gt; 0)
                                  deltaY = -y;
                              else if (y + deltaY &lt; -bottom)
                                  deltaY = -(y + bottom);
                          } else if (scaleHeight &lt; height) {
                              deltaY = 0;
                              if (x + deltaX &gt; 0)
                                  deltaX = -x;
                              else if (x + deltaX &lt; -right)
                                  deltaX = -(x + right);
                          } else {
                              if (x + deltaX &gt; 0)
                                  deltaX = -x;
                              else if (x + deltaX &lt; -right)
                                  deltaX = -(x + right);
  
                              if (y + deltaY &gt; 0)
                                  deltaY = -y;
                              else if (y + deltaY &lt; -bottom)
                                  deltaY = -(y + bottom);
                          }
                          matrix.postTranslate(deltaX, deltaY);
                          last.set(curr.x, curr.y);
                          PosterActivity.isTouched=true;
  
                      }
                      break;
  
                  case MotionEvent.ACTION_UP: {
                      mode = NONE;
                      int xDiff = (int) Math.abs(curr.x - start.x);
                      int yDiff = (int) Math.abs(curr.y - start.y);
                      if (xDiff &lt; CLICK &amp;&amp; yDiff &lt; CLICK) {
                          Log.v("ACTION_UP", "ACTION_UP");
                          mPosX = curr.x;
                          mPosY = curr.y;
  
                          PosterActivity.isTouched=true;
                          performClick();
  
                      }
                      //setImageMatrix(matrix);
                      //invalidate();
                      break;
                  }
                  case MotionEvent.ACTION_POINTER_UP:
                      mode = NONE;
                      break;
                  }
                  setImageMatrix(matrix);
                  invalidate();
                  return true; // indicate event was handled
              }
  </code></pre>