我的用户界面有2个LinearLayout,layout1和layout2。
并使用以下代码显示对话框:

private AlertDialog MyDialog;
public void adddialog() {
    AlertDialog.Builder MyBuilder = new AlertDialog.Builder(this);
    MyBuilder.setTitle("Title")
    MyBuilder .setView(ListView);
    MyDialog = MyBuilder.create();
}


我想将对话框的位置设置在layout2的右上角。
我怎么到达?

最佳答案

private AlertDialog MyDialog;
public void adddialog()
{
  AlertDialog.Builder MyBuilder = new AlertDialog.Builder(this);
  MyBuilder.setTitle("Title")
  MyBuilder .setView(ListView);
  MyDialog = MyBuilder.create();
  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  WindowManager.LayoutParams dialogParam = MyDialog.getWindow().getAttributes();

 dialogParam.gravity = Gravity.TOP | Gravity.RIGHT;
// dialogParam.x = 100;   //x position
// dialogParam.y = 100;   //y position

 MyDialog.show();
}

关于android - 在Android上的布局中显示对话框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16334153/

10-10 16:23