On reference of this thread: android: move a view on touch move (ACTION_MOVE)
I want to move all Objects (for example two ImageView) if I move finger around the screen.
What I have done so far:
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.touchmoveimage);
    background = (ImageView) findViewById(R.id.background);
    image = (ImageView) findViewById(R.id.image);
    root = (ViewGroup) findViewById(R.id.root);
    root.setId(R.id.root);
    image.setId(R.id.image);
    background.setId(R.id.background);
    MyTouchListener touchListener = new MyTouchListener();
    Bitmap bitmap;
    bitmap = decodeFile(R.drawable.background);
    background.setImageBitmap(bitmap);
    image.setImageResource(R.drawable.fire);
    image.setOnTouchListener(touchListener);
    background.setOnTouchListener(touchListener);
    ((ViewGroup) image.getParent()).removeView(image);
    ((ViewGroup) background.getParent()).removeView(background);
    root.addView(background);
    root.addView(image);
And this is MyTouchListener
public class MyTouchListener implements View.OnTouchListener{
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch (view.getId()) {
            case R.id.background:
                ImageView view2 = (ImageView) view;
                view2.setScaleType(ImageView.ScaleType.MATRIX);
                float scale;
                dumpEvent(event);
                //Handle touch events here...
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN: //first finger down only
                        savedMatrix.set(matrix);
                        start.set(event.getX(), event.getY());
                        Log.d(TAG, "mode=DRAG");
                        mode = DRAG;
                        break;
                    case MotionEvent.ACTION_UP://first finger lifted
                    case MotionEvent.ACTION_POINTER_UP: //second finger lifted
                        mode = NONE;
                        Log.d(TAG, "mode=NONE");
                        break;
                    case MotionEvent.ACTION_POINTER_DOWN: //first and second finger down
                        oldDist = spacing(event);
                        Log.d(TAG, "oldDist=" + oldDist);
                        if (oldDist > 10f) {
                            savedMatrix.set(matrix);
                            midPoint(mid, event);
                            mode = ZOOM;
                            Log.d(TAG, "mode=ZOOM");
                        }
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if (mode == DRAG) {
                            matrix.set(savedMatrix);
                            image.setImageMatrix(matrix);
                            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y); //create the transformation in the matrix of points
                        } else if (mode == ZOOM) {
                            float[] f = new float[9];
                            //pinch zooming
                            float newDist = spacing(event);
                            Log.d(TAG, "newDist=" + newDist);
                            if (newDist > 10f) {
                                matrix.set(savedMatrix);
                                scale = newDist / oldDist; //setting the scaling of the matrix...
                                //if scale > 1 means zoom in
                                // if scale < 1 means zoom out
                                matrix.postScale(scale, scale, mid.x, mid.y);
                                //scale = Math.max(MIN_ZOOM, Math.min(scale, MAX_ZOOM));
                            }
                            matrix.getValues(f);
                            float scaleX = f[Matrix.MSCALE_X];
                            float scaleY = f[Matrix.MSCALE_Y];
                            //Einstellungen minimaler oder maximaler zoom
                            if (scaleX <= MIN_ZOOM) {
                                matrix.postScale((MIN_ZOOM) / scaleX, (MIN_ZOOM) / scaleY, mid.x, mid.y);
                            } else if (scaleX >= MAX_ZOOM) {
                                matrix.postScale((MAX_ZOOM) / scaleX, (MAX_ZOOM) / scaleY, mid.x, mid.y);
                            }
                        }
                        break;
                }
                view2.setImageMatrix(matrix); //display the transformation on screen
                break;
            case R.id.image:
                final int X = (int) event.getRawX();
                final int Y = (int) event.getRawY();
                //Definition MotionEvent.ACTION_MASK: Bit mask of the parts of the action code that are the action itself.
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:
                        RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
                        _xDelta = X - lParams.leftMargin;
                        _yDelta = Y - lParams.topMargin;
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_POINTER_DOWN:
                        break;
                    case MotionEvent.ACTION_POINTER_UP:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
                                .getLayoutParams();
                        layoutParams.leftMargin = X - _xDelta;
                        layoutParams.topMargin = Y - _yDelta;
                        layoutParams.rightMargin = -250;
                        layoutParams.bottomMargin = -250;
                        view.setLayoutParams(layoutParams);
                        break;
                }
                root.invalidate();
                break;
        }
        return true;
    }
}
And this is the xml of my Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/skizze"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix" />
    <ImageView
        android:id="@+id/feuerloescherID"
        android:layout_width="55dp"
        android:layout_height="55dp"
        android:layout_alignParentTop="false"
        android:layout_gravity="center_horizontal|top" />
</RelativeLayout>
I hope I've given you all relevant informations. What do I have to add/change in my Code to move ALL Objects in my Layout?
Kind Regards!
 
    