我有一个Activity
它使用
getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
确定可用的屏幕空间并决定放置图像的位置。
单击硬件“后退”按钮离开后返回活动Activity
,矩形值为
(0,0,800,480)
但是,在单击硬件“主页”按钮后返回活动以离开Activity
,矩形值为
(0,38,800,480)
这会影响显示和图像的放置。
如何确保调用时获得一致的值
getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
不管我如何离开应用程序?
更新:感谢@Reno 帮助测试;它似乎依赖于 Android 版本而不是设备。
好吧,如果您阅读源代码中的注释,它承认这种方法有点损坏
public void getWindowVisibleDisplayFrame(Rect outRect) {
if (mAttachInfo != null) {
try {
mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect);
} catch (RemoteException e) {
return;
}
// XXX This is really broken, and probably all needs to be done
// in the window manager, and we need to know more about whether
// we want the area behind or in front of the IME.
final Rect insets = mAttachInfo.mVisibleInsets;
outRect.left += insets.left;
outRect.top += insets.top;
outRect.right -= insets.right;
outRect.bottom -= insets.bottom;
return;
}
对于
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)