How to get or compute the width/height of an inflated view

Viewed 15833

How do I compute the width and height of an inflated View if the parent is a PopupWindow, not a ViewGroup? I cannot use LayoutInflator.inflate(int resId, ViewGroup parent, attachToRoot boolean) because PopupWindow is not a ViewGroup, so I use LayoutInflator.inflate(int resId) instead, but after that I getWidth() and getHeight() return zero :(

I need to resize the PopupWindow to fit the View, but cannot do so until the View has a parent. Do I have a chicken-and-egg problem?

By the way the View is a subclass of RelativeView so calculating it manually is essentially out of the question.

Thanks in advance, Barry

3 Answers
Related