Nexus 4 屏幕底部的 96 个像素缺失 - 获取 Nexus 4 的 Window 尺寸

Bottom 96 Pixels of Nexus 4 Screen Missing - Get Window Dimensions for Nexus 4

我正在开发一个在 main.xml 中包含 RelativeLayout 的应用程序。通过 onclick 事件将其他 ChildView 动态添加到 RelativeLayout。

当我运行应用程序时,为我的nexus 4重新调整的displayHeight是1184,虽然它应该是1280。本质上,屏幕的高度被缩短了,但我不知道为什么。我将 layout_height 设置为 match_parent 但是 mFrame,即 RelativeLayout,returns 1184.

有谁知道为什么在调用 .getHeight() 时没有返回显示的全长?

已覆盖 onWindowsChanged() 以检测正在使用的设备的屏幕尺寸:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {

        // Get the size of the display so this View knows where borders are
        mDisplayWidth = mFrame.getWidth();
        mDisplayHeight = mFrame.getHeight();

        Log.v(TAG, "mDisplayWidth & mDisplayHeight -  w:" + mDisplayWidth + " h: " + mDisplayHeight);
    }
}

这部分代码的logcatreturns:

mDisplayWidth & mDisplayHeight -  w:768 h: 1184

我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FF444444"
        android:id="@+id/frame">

</RelativeLayout>

Nexus 4 的显示屏为 1280 x 768,但是 Android 系统按钮占据了屏幕的一部分。

您的身高 returns 1184,因为这是显示屏的完整高度(1280 像素)减去 Android 系统按钮占用的 96 像素。