0

I want to change position of PopupWindow dynamically. Have used the following method:

public void showAtLocation (View parent, int gravity, int x, int y)

But sometime PopupWindow shows out of screen. So which relative parameter should I use for changing the value x and y (like layout height or width etc)?

Opal
  • 81,889
  • 28
  • 189
  • 210
JithinMechery
  • 53
  • 2
  • 9

2 Answers2

1

You need to use

public void update(int x, int y, int width, int height)

metod in PopupWindow

Georg
  • 73
  • 7
0

Try this

 AlertDialog dialog = builder.create();
 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
 WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();



wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100;   //x position
wmlp.y = 100;   //y position

dialog.show();

where X and Y are in pixels.

If you just want to move the alert dialog down, then

alertDialog.getWindow().getAttributes().verticalMargin = 0.2F;

Aniruddha
  • 4,477
  • 2
  • 21
  • 39
  • Thank you for your response Aniruddha, But In my program the x and y values assign dynamically, so user perspective they just know give two integer value two x & y. if they put x=500 , y =750 then the popup display outside the screen . so hoe can i overcome the situation when the user use different screen size android device. – JithinMechery Jul 01 '14 at 10:21