在Android(安卓)7.0上PopupWindow.showAsDropDown不起作用的解决方法
16lz
2022-04-21
创建一个类,继承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);;
更多相关文章
- android -------- 混淆打包报错(warning - InnerClass annotatio
- Android开发环境配置
- Android(安卓)GoogleMap Overlay (图层标记)
- Android外接扫码枪监听普通输入事件
- Android入门:Button
- 解决Conversion to Dalvik format failed with error 1
- unity3d IL2CPP for android
- Android之应用程序监听开机启动自启动应用程序
- android 报错问题解析