When you click on a button and pop-up Popupwindow, Popupwindow the lower left corner of the default button alignment, but if Popupwindow is the case, there will be dislocation, especially in different sizes of the flat, that dislocation is not the general wrong, And Android itself only provides several ways to set the Popupwindow display location
- Showasdropdown (View anchor, int xoff, int yoff) with the lower left corner of the anchor as the reference point, define the offset
- Showasdropdown (Android.view.View) is the reference point in the lower left corner of the anchor, not offset
- Showatlocation (View parent, int gravity, int x, int y) in parent primary container, gravity to align reference point, define offset
It is recommended to use the Showasdropdwon method.
This is to let the Popupwindow be centered, so you need to define the lateral displacement offset (similar to other locations).
int Xoff = window.getwidth ()/2-parent.getwidth ()/20);
Android Popupwindow Display location settings