android自定义dialog窗体的大小和位置
2014-12-14 09:47
405 查看
不设置dialog窗体的位置和大小:
效果如下:
通过获取屏幕的像素,按比例设置弹出dialog窗体的大小和位置:
View dialogView = getView(context, R.layout.dialog_view); final Dialog mAlertDialog = new Dialog(context, R.style.theme_dialog); mAlertDialog.setContentView(dialogView); mAlertDialog.show();
效果如下:
通过获取屏幕的像素,按比例设置弹出dialog窗体的大小和位置:
View dialogView = getView(context, R.layout.dialog_view); final Dialog mAlertDialog = new Dialog(context, R.style.theme_dialog); mAlertDialog.setContentView(dialogView); //获取屏幕宽高 WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width =display.getWidth(); int height=display.getHeight(); Window dialogWindow = mAlertDialog.getWindow(); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP); //lp.x与lp.y表示相对于原始位置的偏移. //将对话框的大小按屏幕大小的百分比设置 lp.x = (int) (width*0.05); // 新位置X坐标 lp.y = (int) (height*0.2); // 新位置Y坐标 lp.width = (int) (width*0.9); // 宽度 lp.height = (int) (height*0.6); // 高度 dialogWindow.setAttributes(lp); mAlertDialog.show();最终效果如下:
相关文章推荐
- Android中自定义Activity和Dialog的位置大小背景和透明度等
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android中自定义Activity和Dialog的位置大小背景和透明度等
- Android自定义对话框(Dialog)位置,大小
- Android自定义Dialog 及位置和大小
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android中自定义Activity和Dialog的位置大小背景和透明度等
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- android 中自定义Dialog的位置和大小的方法
- 90 Android Dialog 自定义 大小 位置
- Android自定义对话框(Dialog)位置 大小
- Android中自定义Activity和Dialog的位置大小背景和透明度等
- Android自定义对话框(Dialog)位置,大小
- android 中自定义Dialog的位置和大小的方法
- Android中自定义Activity和Dialog的位置大小背景和透明度等