Zoom on all ImageViews which are in different layout
<p>I have two layouts and ImageViews inside it. First layout Imageview will behave as a background and other layouts image view as different objects. Now I want to zoom imageViews of both  but objects should only be selected  and not the background. I mean background should just be used for zoom. </p>

<p>This is my xml </p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;

   &lt;ImageView android:id="@+id/test"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/hh_gmw01"
         android:scaleType="matrix"
         android:tag="0"
         /&gt;

   &lt;RelativeLayout 
       android:id="@+id/LParentLayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;

        &lt;ImageView
        android:id="@+id/imageView100"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="388px"
        android:layout_marginTop="269px"
        android:contentDescription="Image1"
        android:src="@drawable/h1"
        android:tag="a" /&gt;

    &lt;ImageView
        android:id="@+id/imageView200"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="147px"
        android:layout_marginTop="99px"
        android:contentDescription="Image1"
        android:src="@drawable/h2"
        android:tag="b" /&gt;
       &lt;/RelativeLayout&gt; 
&lt;/RelativeLayout&gt;
</code></pre>

<p>and this is my code for the ImageVIew matrix but this gets applied only on one imageview</p>

<pre><code>public class GamePlayActivity extends Activity implements OnTouchListener{


    private static final String TAG = "Touch";
    // These matrices will be used to move and zoom image
    Matrix matrix = new Matrix();
    Matrix savedMatrix = new Matrix();
    Matrix savedMatrix2 = new Matrix();
    float mx,my;
    private static final int WIDTH = 0;
     private static final int HEIGHT = 1;
    // We can be in one of these 3 states
    static final int NONE = 0;
    static final int DRAG = 1;
    static final int ZOOM = 2;
    int mode = NONE;

    // Remember some things for zooming
    PointF start = new PointF();
    PointF mid = new PointF();
    float oldDist = 1f;
    int mwidth;
       int mheight;


    static int ObjectsFound;
    //ArrayList&lt;ImageView&gt; hiddenObjects;
     Toast msg;
     int click_Locn_x,click_Locn_y;
    int objectCollected=0;
    View level=null;
    ShowPopUpWindow popup;
    static View[]_hiddenObjects;
    HiddenObject _ho;
    ImageView im,img1,img2;

     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

                setContentView(R.layout.gameplay);

            LinearLayout layouts = (LinearLayout) findViewById(R.id.GameplayRootLayout);
            LayoutParams lp = layouts.getLayoutParams();




            // ViewGroup where n number of view is going to added
            ViewGroup layout= (ViewGroup) findViewById(R.id.GamePlayScreen);


            // inflating the layout depending on the level 
            level = View.inflate(this, R.layout.main, null);
        //  level.setOnTouchListener(this);

            Log.d("Print", "Search ID : " + R.id.test);
            ImageView imf= (ImageView) level.findViewById(R.id.test);
            imf.setOnTouchListener(this);
            RelativeLayout rl=(RelativeLayout) level.findViewById(R.id.LParentLayout);
            img1= (ImageView) rl.findViewById(R.id.imageView100);
            img1.setOnTouchListener(this);
            img2= (ImageView) rl.findViewById(R.id.imageView200);
            img2.setOnTouchListener(this);



        // adding level bg for the respective selected level
            layout.addView(level);

    }   




    @Override
    public boolean onTouch(View objectClicked, MotionEvent event) {

        // TODO Auto-generated method stub



        //findViewById(objectClicked.getId());
        Log.d("Check", " Image Tag " +  objectClicked.getTag().toString());
        if ((Integer.parseInt(objectClicked.getTag().toString())==0))
        {

            ImageView img = (ImageView) objectClicked;  

         float curX, curY;

           // Handle touch events here...
         switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
           case MotionEvent.ACTION_DOWN:
              savedMatrix.set(matrix);
               mx = (int)event.getX();
               my = (int)event.getY();
              mode = DRAG;
              break;
           case MotionEvent.ACTION_POINTER_DOWN:
              oldDist = spacing(event);
              Log.d(TAG, "oldDist=" + oldDist);
              if (oldDist &gt; 10f) {
                 savedMatrix.set(matrix);
                 midPoint(mid, event);
                 mode = ZOOM;
                 Log.d(TAG, "mode=ZOOM");
              }
              break;
         case MotionEvent.ACTION_UP:
              mode = NONE;
              savedMatrix.set(matrix);
             break;
           case MotionEvent.ACTION_MOVE:
              if (mode == DRAG) {
                  curX = event.getX();
                  curY = event.getY();
                 matrix.postTranslate(-(mx - curX), -(my - curY));

                  mx = curX;
                  my = curY;
                  break;
              }
              else if (mode == ZOOM) {
                 float newDist = spacing(event);
                 float arr1[]=new float[9];
                 Log.d(TAG, "newDist=" + newDist);
                 if (newDist &gt; 10f) {
                    savedMatrix2.set(matrix);
                    matrix.set(savedMatrix);
                    float scale = newDist / oldDist;
                    matrix.setScale(scale, scale,mid.x,mid.y);
                    matrix.getValues(arr1);

                    // keeping tab on Zooming ...Allowed only to 3.0 level  
                    if((arr1[Matrix.MSCALE_X]) &gt;2.0){
                        matrix.set(savedMatrix2);
//                      Log.d("Print", "Value Left"  + img.getLeft()+ " Value Right "+ img.getRight());
                    }


                 }
              }
              break;
           }
         float arr[]=new float[9];
         matrix.getValues(arr);
         Log.d("Print", arr[0] + "," + arr[1] + "," + arr[2] + "," + arr[3] + "," + arr[4] + "," + arr[5] + "," + arr[6] + "," + arr[7] + "," + arr[8]);



         img.setImageMatrix(matrix);
         img1.setImageMatrix(savedMatrix2);
         img2.setImageMatrix(savedMatrix2);
         fixing(img);
         return true;

        }
        else
        {
            ImageView img2 = (ImageView) objectClicked; 
            img2.setVisibility(View.INVISIBLE);


            msg = Toast.makeText(GamePlayActivity.this, "Object Found",
                    100);
            msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2,
                    msg.getYOffset() / 2);
            msg.show();
            Log.d("Check", " I am Imageview Object FOund layout check");

            return true;

        }

        }



    /** Calculate the mid point of the first two fingers */
    private void midPoint(PointF point, MotionEvent event) {
       float x = event.getX(0) + event.getX(1);
       float y = event.getY(0) + event.getY(1);
       point.set(x / 2, y / 2);
    }

    private float spacing(MotionEvent event) {
        if(event.getPointerCount() == 2){
          float x = event.getX(0) - event.getX(1);
          float y = event.getY(0) - event.getY(1);
          return FloatMath.sqrt(x * x + y * y);
        }
        return 0;
      }

        private void fixing(View v) {
            // TODO Auto-generated method stub

            if (SmallerThanIdentity(matrix)) {
                resetView(v);
            }

        }

        public static boolean SmallerThanIdentity(android.graphics.Matrix m) {
            float[] values = new float[9];
            m.getValues(values);
            return ((values[0] &lt; 1.0) || (values[4] &lt; 1.0) || (values[8] &lt; 1.0));
        }

        public void resetView(View v) {
            ImageView view = (ImageView) v;
            matrix = new Matrix();

            view.setScaleType(ImageView.ScaleType.MATRIX);
            view.setImageMatrix(matrix);
        }

}
</code></pre>

<p>Thanks for the help ...</p>
