Android PopupWindow and WRAP_CONTENT don't work together

Boris picture Boris · Apr 18, 2013 · Viewed 27.8k times · Source

I open a popu window like this:

mInfoPopup = new PopupWindow(layout, 400, 600, true);
mInfoPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

The window then gets the exact size specified (400x600) and does NOT adjust its size to its content. What do I need to change so that the popup window will actually wrap around its contents?

Answer

Gomino picture Gomino · Jul 2, 2013

Simply changed the way you create it by:

PopupWindow popupMenu = new PopupWindow(layout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);