title: Handling Pinch Zoom
body: <p>I've a class which extends <code>Fragment</code>. I'm trying to perform pinch zoom. But its not working. I've tried every single piece of code but its not working.
  I don't get any error in the output no debugger error its just the thing it doesn't work when we try to expand it from our fingers remains intact.
  My xml file goes like that : </p>
  
  <pre><code>&lt;ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:src="@drawable/mypic"
      android:scaleType="matrix"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" /&gt;
  </code></pre>
  
  <p>and the Testing Map activity goes like that :</p>
  
  <pre><code>public class MapFragment extends Fragment implements View.OnTouchListener{
  
  
  private ScaleGestureDetector SGD;
  private ImageView imageView;
  private float scale = 1f;
  private Matrix matrix = new Matrix();
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_map, container, false);
      imageView = (ImageView)view.findViewById(R.id.imageView);
      SGD = new ScaleGestureDetector(getContext(),new ScaleListener());
      return view;
  }
  
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      SGD.onTouchEvent(event);
      return true;
  }
  
  
  private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener{
      @Override
      public boolean onScale(ScaleGestureDetector detector) {
          scale  = scale*detector.getScaleFactor();
          scale = Math.max(0.1f,Math.min(scale,5.0f));
          matrix.setScale(scale,scale);
          imageView.setImageMatrix(matrix);
          return true;
      }
  }}
  </code></pre>