title: Android - zoom in/out RelativeLayout with spread/pinch
body: <p>I have an activity with a <code>RelativeLayout</code> and a private class in it, which extends the <code>SimpleOnScaleGestureListener</code>. In the <code>onScale</code> method of the listener I'd like to zoom in/out of the whole layout (everything the user sees) with the user spreading/pinching his fingers.</p>
  
  <p>I'd like the changes to the layout NOT to be permanent, i.e. when the spread/pinch gesture is over I'd like the layout to go back to what it was in first place (any resetting could be done in the <code>onScaleEnd</code> method of the <code>SimpleOnScaleGestureListener</code> for example).</p>
  
  <p>I've tried to implement it via calling <code>setScaleX</code> and <code>setScaleY</code> on the <code>RelativeLayout</code> and also by using a <code>ScaleAnimation</code>. Neither resulted in smooth zooming (or anything that could at all be called zooming). Is it even possible to zoom in/out a <code>RelativeLayout</code>?</p>
  
  <p>The only idea I have left would be reading a screenshot from the cache and putting it as an <code>ImageView</code> on top of the whole layout and the zoom in/out of this image via <code>setImageMatrix</code>. I have no clue, however, how to implement this.</p>
  
  <p>May layout also contains a container for a fragment, which is empty at the time the zooming is supposed to be possible. In the <code>onScaleEnd</code> gesture, the fragment is put into it's container (already implemented and working fine). Here is my layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/layout_pinch"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#ffffff" &gt;   
  
  
  &lt;!-- Layout containing the thumbnail ImageViews --&gt;
  &lt;LinearLayout
      android:id="@+id/thumbnail_group_pui"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c1"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c2"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c3"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c4"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c5"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c6"/&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/tn_c7"/&gt;
  
  &lt;/LinearLayout&gt;
  
  
  &lt;!-- Layout containing the dashed boxes --&gt;
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="152dp"
      android:layout_centerVertical="true"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
     &lt;ImageView
          android:layout_width="177dp"
          android:layout_height="match_parent"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:background="@drawable/dashed_box"/&gt;
  
  &lt;/LinearLayout&gt;
  
  
  &lt;!-- Container for the fragments --&gt;
  &lt;FrameLayout
      android:id="@+id/fragment_container_pui"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>
  I found these two related topics:<br>
  <a href="https://stackoverflow.com/questions/6378904/extending-relativelayout-and-overriding-dispatchdraw-to-create-a-zoomable-vie">Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup</a><br>
  <a href="https://stackoverflow.com/questions/9192424/zoom-content-in-a-relativelayout">Zoom Content in a RelativeLayout</a></p>
  
  <p>I did not get the implementation, however. What other methods do I have to include in the extended class to actually scale the layout or reset it?</p>