设置AlertDialog位置大小(模拟windows右击菜单)

来源:互联网 发布:知乎名字来源 编辑:程序博客网 时间:2024/05/29 18:16
menuDialog = new AlertDialog.Builder(this).create();menuDialog.setView(menuView);menuDialog.show();dlgSetting();menuDialog.show();


 

private boolean dlgSetting(){   int[] location = new  int[2];   WindowManager m = getWindowManager();    Display d = m.getDefaultDisplay();   View view = mGridView.getChildAt(nCurPosition);    if(view==null)    return false;   view.getLocationInWindow(location);         WindowManager.LayoutParams lp = menuDialog.getWindow().getAttributes();               lp.x = -(d.getWidth()/2-location[0]-view.getWidth());   //新位置X坐标               lp.y = -(d.getHeight()/2-location[1]-view.getHeight()); //新位置Y坐标               lp.height = 200;//对话框高            lp.width = 150;//对话框宽         menuDialog.getWindow().setAttributes(lp);         menuDialog.dismiss();         return true; }