我想动态更改PopupWindow的位置。使用了以下方法:
public void showAtLocation (View parent, int gravity, int x, int y)
但是有时PopupWindow显示在屏幕外。因此,应该使用哪个相对参数来更改x和y值(如布局高度或宽度等)?
尝试一下
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();
其中X和Y以像素为单位。
如果只想将警报对话框下移,则
alertDialog.getWindow().getAttributes().verticalMargin = 0.2F;
您需要使用
public void update(int x, int y, int width, int height)
在PopupWindow中的方法