2017-01-03 65 views
7

这里是我的秀PopupWindowPopupWindow高于在一些设备状态栏

View rootView = activity.getWindow().getDecorView().getRootView(); 
mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, 0, 0); 

代码当我测试它SamsungNexus设备显示它下面状态栏
然而,当我测试在Sony设备它显示以上状态栏(如下图)

那么哪个设备显示正确或我做错了什么? 任何帮助或建议将是巨大的赞赏

enter image description here

回答

1

我解决我的问题,通过创建一个临时Viewtop-lefttopLeftView在下面的代码)。
后来,当我展示PopupWindow,我会在(0, the y coordinate of topLeftView)显示它不是(0,0)

View topLeftView = findViewById(R.id.top_left_View); 
int topLeftPos[] = new int[2]; 
topLeftView.getLocationOnScreen(topLeftPos); 

mPopupWindow.showAtLocation(topLeftView, Gravity.NO_GRAVITY, 0, topLeftPos[1]); 

我觉得这个解决方案将所有设备

+0

它看起来像索尼设备的Android的味道工作计算左上角作为物理左上角,而Nexus和三星设备计算不包括状态栏的左上角。 – ucsunil