在创建dialog或者构造方法出加入如下代码就可以解决问题、
Window window = dialog.getWindow();
if (dialog != null && window != null) {
WindowManager.LayoutParams attr = window.getAttributes();
if (attr != null) {
attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;
attr.width = ViewGroup.LayoutParams.WRAP_CONTENT;
attr.gravity = Gravity.CENTER;//设置dialog 在布局中的位置
}
}
本文介绍了一种通过修改Window属性来调整Dialog在屏幕中位置的方法。具体实现方式为:获取Dialog的Window实例,设置LayoutParams属性包括高度、宽度为自适应内容,并调整Gravity使其居中。
3084

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



