您的位置:首页 > 移动开发 > Android开发

Android7.0上PopupWindow的showAsDropDown位置问题

2017-04-14 20:31 549 查看

Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);



不判断24 统统加上,可以解决弹出位置不在正下方的问题


问题说明

我的popupWindow是用来展示listView的,近期在Android7.0手机上测试发现
showAsDropDown(view)
展示时发现会充满屏幕,而不是展示在
view
的下方,测试发现在7.0以下和7.1系统下都没有类似问题。


问题解决

重写
showAsDropDown(view)
,如下:
@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);
}
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: