How to move a view in Android?

WindowManager maintains at least two more instances of LayoutParams class for each view, besides that one in the View itself.

Check updateViewLayout method of WindowManager, this part in particular:

    view.setLayoutParams(wparams);

    synchronized (this) {
        int index = findViewLocked(view, true);
        ViewRoot root = mRoots[index];
        mParams[index] = wparams;
        root.setLayoutParams(wparams, false);
    }

I believe that you can make some mess by calling layout directly. Use WindowManager.updateViewLayout instead. It will be slower, but safe (just IMO).


UPDATE

[From: https://stackoverflow.com/a/11188273/327011 ]

WindowManager windowsManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)

WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.x = <new X coord>;
windowParams.y = <new Y coord>
windowParams.height = myImageView.getHeight();
windowParams.width = myImageView.getWidth();
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowParams.format = PixelFormat.TRANSLUCENT;
            windowParams.windowAnimations = 0;

windowManager.updateViewLayout(myImageView, windowParams);

The easiest way to move a view with the finger is using the setTranslationX and setTranslationY from the View class.

http://developer.android.com/reference/android/view/View.html#setTranslationX(float)

You can also change the margins on the View LayoutParams to move if you are targeting api < 11.

I believe that moving the item on the onLayout or onDraw function worse because the view already has these options above and drawing your view manually can become complex as you add more items and different views.