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

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;
 }


 

你可能感兴趣的:(windows,null)