title: Combine Drag and Drop and Scaling
body: <p>I've implemented a movable image view that I can move around with a finger and also scale. I use the drag and drop framework to move it around (because I also need it drag and droppable), and I have a <code>ScaleGestureDetector.SimpleOnScaleGestureListener</code> that handles the scaling. The <code>MovableImageView</code> extends the normal <code>ImageView</code> form Android. When a user touches the image view, the method <a href="http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29" rel="nofollow">onTouchEvent(MotionEvent event)</a> is called. This method looks like this:</p>
  
  <pre><code>public boolean onTouchEvent(MotionEvent event)
  {
     scaleDetector.onTouchEvent(event);
     startDragNDrop();
     return true;
  }
  </code></pre>
  
  <p><code>startDragNDrop()</code> looks like this:</p>
  
  <pre><code>private void startDragNDrop() {
      // Create a new ClipData.
      // This is done in two steps to provide clarity. The convenience method
      // ClipData.newPlainText() can create a plain text ClipData in one step.
  
      // Create a new ClipData.Item from the ImageView object's tag
      ClipData.Item item = new ClipData.Item(mediaItem.getMediaIdentifier());
  
      // Create a new ClipData using the tag as a label, the plain text MIME type, and
      // the already-created item. This will create a new ClipDescription object within the
      // ClipData, and set its MIME type entry to "text/plain"
      String[] mimeType =  {ClipDescription.MIMETYPE_TEXT_PLAIN};
      ClipData dragData = new ClipData((CharSequence) this.getTag(),mimeType,item);
  
      // Instantiates the drag shadow builder.
      DragShadowBuilder myShadow = new ZPACDragShadowBuilder(this);
  
      actualyDraggedView = this;
  
      // Starts the drag
      this.startDrag(dragData,  // the data to be dragged
                     myShadow,  // the drag shadow builder
                     null,      // no need to use local data
                     0);        // flags (not currently used, set to 0)
  }
  </code></pre>
  
  <p>It basically creates the dragshadow and starts the dragging operation.</p>
  
  <p>The implementation of <a href="http://developer.android.com/reference/android/view/ScaleGestureDetector.SimpleOnScaleGestureListener.html#onScale%28android.view.ScaleGestureDetector%29" rel="nofollow">onScale()</a>, that is called after <code>scaleDetector.onTouchEvent(event)</code> is the following:</p>
  
  <pre><code>public boolean onScale(ScaleGestureDetector detector) {
      float scaleFactor = MovableImageView.this.SCALE_FACTOR;
      scaleFactor *= detector.getScaleFactor();
  
      // Don't let the object get too small or too large.
      scaleFactor = Math.max(0.1f, Math.min(scaleFactor, 2.0f));
  
      int width = (int) (MovableImageView.this.getWidth()*scaleFactor);
      int height = (int) (MovableImageView.this.getHeight()*scaleFactor);
  
      Log.e("MovableImageView", "Scale Gesture Captured. Scaling Factor " + scaleFactor + " old width " + MovableImageView.this.getWidth() + ", new width " + width);
  
      AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(width, height, MovableImageView.this.getLeft(), MovableImageView.this.getTop());
  
      parentLayout.updateViewLayout(MovableImageView.this, layoutParams);
      invalidate();
      return true;
  }
  </code></pre>
  
  <p>The field <code>SCALE_FACTOR</code> is a float and the value is <code>1.f</code>. And <code>parentLayout</code> is an extended AbsoluteLayout that manages the position and the size of the ImageView on the screen.</p>
  
  <p>My problem is that the scaling does not function, only the drag and drop. No scaling is performed, only moving around the view works. If I comment out the linke <code>startDragNDrop()</code>, then the scaling works, but moving around the view obviously not. Has anybody a better idea to combine these to things in an imageview?</p>