reprint: http://orgcent.com/android-popupwindow-showasdropdown-showatlocation/
the previous article details the usage of popupwindow (Position, animation, and focus). For details, see the usage of popupwindow in Android (Position, animation, and focus ). The following describes how to hide, display, and display position (showatlocation/showasdropdown) of popupwindow ).
1. Hide popupwindow
1 2 3 4 |
Final Popupwindow window = Mpagestatwin ; If ( Null ! = Window && Window. Isshowing ( ) ) { Win. Dismiss ( ) ; } |
2. Display and Position Setting of popupwindow
1 |
Window.Showatlocation ( Parent, gravity. Right | Gravity. Bottom , 10 , 10 ) ; |
The first parameter specifies the popupwindow anchor view, that is, the view to which the popupwindow is attached.
The second parameter specifies the starting point as the bottom right corner of the parent, and the third parameter sets the source point as the bottom right corner of the parent, with each offset of 10 pixels to the left and top.
1 2 3 4 |
// Use popupwindow as the anchor drop-down window. It is displayed in the lower left corner of anchor. Window. Showasdropdown ( Anchor) ; // Xoff, yoff offset based on the lower left corner of anchor. Window. Showasdropdown ( Anchor, xoff, yoff ) ; |
If there is not enough space to display popupwindow, the lower left corner of popupwindow will be displayed in the upper left corner of anchor.