I have some popups on my app, it's fullscreen and the following code:
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);
Make the window show centered.
But I have another Activity which is not fullscreen, when the popup opens it's right-down from where it's need to be.
Trying to figure out why this happens, I think the showAtLocation shows it's relative to the current Activity, but I need to show it relative to the display.
How can I do that? Or there's a simpler way to just the popup just centered?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…