【发布时间】:2011-08-29 03:38:30
【问题描述】:
我的应用上有一些弹出窗口,它是全屏的,代码如下:
content.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
content.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
int screenHeight = windowManager.getDefaultDisplay().getHeight();
int x = screenWidth / 2 - content.getMeasuredWidth() / 2;
int y = screenHeight / 2 - content.getMeasuredHeight() / 2;
window.showAtLocation(content, Gravity.NO_GRAVITY, x, y);
使窗口居中显示。
但我有另一个不是全屏的 Activity,当弹出窗口打开时,它从需要的位置右下。
试图弄清楚为什么会发生这种情况,我认为 showAtLocation 显示它与当前 Activity 相关,但我需要相对于显示器显示它。
我该怎么做?还是有更简单的方法让弹出窗口居中?
【问题讨论】:
标签: android android-layout popup