api 25 PopupWindow会占据整个屏幕
2024-08-25 21:10:50
解决方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // Android 7.x中,PopupWindow高度为match_parent时,会出现兼容性问题,需要处理兼容性
int[] mLocation = new int[2];
stephenCommonTopTitleView.getTopTitleView().getLocationInWindow(mLocation);
int offsetY = mLocation[1] + stephenCommonTopTitleView.getTopTitleView().getHeight();
if (Build.VERSION.SDK_INT >= 25) { // Android 7.1中,PopupWindow高度为 match_parent 时,会占据整个屏幕
//故而需要在 Android 7.1上再做特殊处理
WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
int screenHeight = wm.getDefaultDisplay().getHeight();
centWinShare.setHeight(screenHeight - offsetY); // 重新设置 PopupWindow 的高度
}
centWinShare.showAtLocation(stephenCommonTopTitleView.getTopTitleView(), Gravity.NO_GRAVITY, 0, offsetY);
} else {
centWinShare.showAsDropDown(stephenCommonTopTitleView.getTopTitleView());
} 思路大概是这样
/*if (Build.VERSION.SDK_INT != 24) {
//只有24这个版本有问题,好像是源码的问题
showAsDropDown(view);
} else {
//7.0 showAsDropDown没卵子用 得这么写
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
//showAsDropDown(view, 0, marginTop);
}*/
最新文章
- xml 读取递归算法
- 分享50款 Android 移动应用程序图标【上篇】
- isScroll代码
- WCF服务中,[DataMember]属性标记的属性一定要有set访问器
- 【大数比较】NYOJ-73
- 符合web标准的网页下拉菜单
- ModSecurity CRS笔记[转]
- 【NOIP2015 DAY1 T3 】斗地主(landlords)
- python脚本对 mysql数据库进行增删改查操作
- bzoj3237(cdq+并查集)
- Spring Boot 自定义日志详解
- 【转载】Window服务器开机后一直处于蓝色屏幕(非蓝屏 crash)状态
- project 2013 工时完成百分比不会自动更新填充
- pytest 6 生成html报告
- Java程序在Linux上运行虚拟内存耗用很大
- oracle sql小结(主要讲横列转换的例子)group by以及wmsys.wm_concat()的使用
- (转)tomcat架构&;session共享
- JS之事件机制
- LeetCode——Convert Sorted List to Binary Search Tree
- Material Design学习之 ProgreesBar