title: android : how to detect zoom in and zoom out gesture detect after pointer up here is my code
body: <p><strong>android : how to detect zoom in and zoom out gesture detect after pointer up here is my code</strong></p>
  <p><strong>Here is my code</strong></p>
  <pre><code>private var initialDistance = 0.toDouble()
  private var lastDistance = 0.toDouble()
  private var ZOOM_IN = false
  private var ZOOM_OUT = false
  
  if (event.pointerCount &gt; 1) {
        
          val action = event.action
          when (action and event.actionMasked) {
              MotionEvent.ACTION_POINTER_DOWN -&gt; {
                  val x1 = event.getX(0).toDouble()
                  val y1 = event.getY(0).toDouble()
                  val x2 = event.getX(1).toDouble()
                  val y2 = event.getY(1).toDouble()
  
                  initialDistance = sqrt((x2 - x1).pow(2.0) - (y2 - y1).pow(2.0))
  
              }
              MotionEvent.ACTION_MOVE -&gt; {
                  val x1 = event.getX(0).toDouble()
                  val y1 = event.getY(0).toDouble()
                  val x2 = event.getX(1).toDouble()
                  val y2 = event.getY(1).toDouble()
  
                  lastDistance = sqrt((x2 - x1).pow(2.0) - (y2 - y1).pow(2.0))
  
                  if (lastDistance &gt; initialDistance)
                      ZOOM_OUT = true
                  else
                      ZOOM_IN = true
              }
              MotionEvent.ACTION_POINTER_UP -&gt; {
                  
                  if (ZOOM_IN) zoomIn()
                  if (ZOOM_OUT) zoomOut()
              }
          }
  </code></pre>
  <p>is this a right formula to measure two pointer distance ?</p>