3

Possible Duplicate:
Show AlertDialog in any position of the screen

As you know Default Dialog has got Gravity properties like Right, Top etc. but is it possible to place Dialog where user touches screen other than default gravity properties?

Using tapped x and y coordinates from onTouch(...) method or something like that, is it possible?

Say for example, I touched (50, 50) x and y coordinates on screen, may not be exactly at that same position but anywhere near to that touched point.

Community
  • 1
  • 1
Braj
  • 2,164
  • 2
  • 26
  • 44

1 Answers1

3

Get the co-ordinates of the action from an event (from say onTouchListener) and then use the dialog's layout params to set the position

WindowManager.LayoutParams params = myDialog.getWindow().getAttributes();
params.x = 300;
params.y = 300;
myDialog.getWindow().setAttributes(params);
Deepak Bala
  • 11,095
  • 2
  • 38
  • 49