在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法

xiaoxiao2021-02-27  370

 创建一个类,继承PopupWindow

public class Solve7PopupWindow extends PopupWindow { public Solve7PopupWindow(View mMenuView, int matchParent, int matchParent1) { super(mMenuView, matchParent,matchParent1); } @Override 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); } } 在new出来即可使用 centerView是你自己想要将popupWindow显示的在这个view的下面 mMenuPopupWindow = new Solve7PopupWindow(mMenuView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); mMenuPopupWindow.showAsDropDown(centerView);;

转载请注明原文地址: https://www.6miu.com/read-3599.html

最新回复(0)