Monday, July 25, 2011

Android x,y =0 plotted view at top-center instead of top-left


WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) mDragView.getLayoutParams();
layoutParams.x = 0;
layoutParams.y = 0;
WindowManager mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
mWindowManager.updateViewLayout(mDragView, layoutParams);

The gravity for this LayoutParams was set as Gravity.TOP.
Instead use:
        mWindowParams.gravity = Gravity.LEFT | Gravity.TOP;
This would plot (0,0) at left top.

Regards.

No comments:

Post a Comment