如何动态修改Android Dialog的位置

时间:2016-04-02 10:52:49

标签: android alertdialog android-dialog

2 个答案:

答案 0 :(得分:0)

AlertDialog.Builder builder = new AlertDialog.Builder(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位置enter code here  wmlp.y = 100; // y位置

dialog.show();

答案 1 :(得分:0)

您需要设置对话框的x,y位置:

AlertDialog.Builder builder = new AlertDialog.Builder (this);

//set your builder
AlertDialog dialog = builder.Create ();
dialog.Window.Attributes.X = 34;
dialog.Window.Attributes.Y = 17;