0
我想动态改变PopupWindow的位置。 曾用下面的方法:动态改变PopupWindow在android的位置
public void showAtLocation (View parent, int gravity, int x, int y)
但有时PopupWindow显示出画面。那么我应该使用哪个相对参数来改变x和y值(比如布局高度或宽度等)?
我想动态改变PopupWindow的位置。 曾用下面的方法:动态改变PopupWindow在android的位置
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;
谢谢您的答复Aniruddha,但在我的程序x和y的值动态分配,所以用户的角度来看,他们只知道给两个整数值两个x&y。如果他们把x = 500,y = 750,那么弹出显示在屏幕之外。所以锄头可以克服用户使用不同屏幕尺寸的Android设备时的情况。 – JithinMechery