I need to show PopupWindow
under one Views
shown on the screen.
How can I calculate coordinates of needed View
and place PopupWindow
under it? Code example are more than welcome. Thanks.
I need to show PopupWindow
under one Views
shown on the screen.
How can I calculate coordinates of needed View
and place PopupWindow
under it? Code example are more than welcome. Thanks.
To get size of the main application screen without stuff like title and notification bars, override the following method in the class generating the screen in question (sizes are measured in pixels):
To get the bottom coordinate of the view under which you want to show the popup:
Now as long as
height - coordinate
is large enough for your popup view, you can simply place the popup like this:Here,
showAtLocation()
takes the parent view as an argument together with gravity and location offsets.you have
getLeft()
andgetBottom()
to get the exact position of the view in the layout. You also havegetWidth()
andgetHeight()
to know the exact space occupied by the view. If you want to position your popup window below a view.You
setLeft()
andsetTop()
methods of the view to position the new popup Window.Locating an already displayed view is fairly easy - here's what I use in my code:
You could then use code similar to what Ernesta suggested to stick the popup in the relevant location:
This would show the popup directly under the original view - no guarantee that there would be enough room to display the view though.