Android7.0 popupWindow想显示在view的下面。 结果弹出的popupWindow显示在屏幕最上面的问题。
解决方案: 重写popupWindow的showAsDropDown方法
1.自己创建一个类集成PopupWindow, 然后重写showAsDropDown方法,创建几个构造方法。代码如下
/** * 作者:Administrator on 2017/8/29 16:27 * desc:activity */ public class MyPopupWindow extends PopupWindow{ @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); } public MyPopupWindow(Context context) { super(context); } public MyPopupWindow(Context context, AttributeSet attrs) { super(context, attrs); } public MyPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public MyPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public MyPopupWindow() { } public MyPopupWindow(View contentView) { super(contentView); } public MyPopupWindow(int width, int height) { super(width, height); } public MyPopupWindow(View contentView, int width, int height) { super(contentView, width, height); } public MyPopupWindow(View contentView, int width, int height, boolean focusable) { super(contentView, width, height, focusable); } }2. 展示的代码 popupWindow为上面自己创建的MyPopupWindow对象。调用的是MyPopupWindow重写showAsDropDown(View view)方法。 popupWindow.showAsDropDown(this);