突然发现Android PopupWindow的showAsDropDown位置失效,听说是Android的sdk版本兼容问题,须要本身重写改方法,安卓的坑真多啊
在网上找了好多方法无论用,最后终于找到一个能够的:
贴一下解决方法,感谢
重写showAsDropDown(view)就解决了。ide
public class SupportPopupWindow extends PopupWindow {ui
public SupportPopupWindow(View contentView, int width, int height){ super(contentView,width,height); } [@Override](https://my.oschina.net/u/1162528) public void showAsDropDown(View anchor) { if(Build.VERSION.SDK_INT >= 24) { Rect rect = new Rect(); anchor.getGlobalVisibleRect(rect); int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom; setHeight(h); } super.showAsDropDown(anchor); } [@Override](https://my.oschina.net/u/1162528) public void showAsDropDown(View anchor, int xoff, int yoff) { if(Build.VERSION.SDK_INT >= 24) { Rect rect = new Rect(); anchor.getGlobalVisibleRect(rect); int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom; setHeight(h); } super.showAsDropDown(anchor, xoff, yoff); }
做者:alwaysGoalong 来源:CSDN 原文:https://blog.csdn.net/alwaysGoalong/article/details/80455427.net