突然發現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