我有我的应用程序的一些弹出窗口,它的全屏和下面的代码:显示PopupWindow集中
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);
使中心的窗口显示。
但我有另一个不是全屏的活动,当弹出窗口从正确的位置开始时,它是从右到下的。
试图找出为什么发生这种情况,我认为showAtLocation显示它是相对于当前的活动,但我需要显示它相对于显示。
我该怎么做?或者有一个更简单的方法来弹出刚居中的弹出窗口?
完美的作品。谢谢 – 2011-09-19 14:18:35
所以,如果我想适应底部,我只是使用这一行'mPw.showAtLocation(v,Gravity.BOTTOM,0,0);'是否可以在xxhpi设备上使用,比如Nexus 5?我有它的问题... – 2014-05-28 00:40:42
你可以告诉日期,这是张贴前xxhpi设备。你的代码应该做你期望的。按照撰写的链接,看到我发布的不同选项的图像示例。 – Bae 2014-05-29 05:36:24