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

来源:互联网 发布:一夫多妻国家知乎 编辑:程序博客网 时间:2024/05/20 14:17

 创建一个类,继承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);;

3 0