I have some popups on my app, it\'s fullscreen and the following code:
content.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
La
View popupView = layoutInflater.inflate(R.layout.index_popviewxml,
null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, true);
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
popupWindow.showAtLocation(anyViewOnlyNeededForWindowToken, Gravity.CENTER, 0, 0);
This will center your view.
It took me 2 hours of pain to figure this out. I didn't need any black magic maths to handle this.
The view is only needed for the window token, it has no other impact on the location.
Gravity tells the layout manager where to start the coordinate system and how to treat those coordinates. I can't find the docs but hacking is showing me that:
I wrote this up over here Android PopupWindow.showAtLocation() and effects of Gravity