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;
}
本文介绍了一种在Android应用中自定义对话框显示位置的方法,通过获取屏幕尺寸、视图位置,并调整对话框属性实现精确布局。
994

被折叠的 条评论
为什么被折叠?



