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



我正在开发一个应用程序,该应用程序在main.xml中包含一个RelativeLayout。其他子视图通过onclick事件动态添加到RelativeLLayout中。

当我运行应用程序时,nexus 4的displayHeight重新调整为1184,尽管它应该是1280。从本质上讲,屏幕的高度被缩短了,但我不知道为什么。我将layout_height设置为match_parent,但是mFrame,即RelativeLayout,返回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);
    }
}

这部分代码的logcat返回:

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系统按钮占据了部分屏幕。

您的身高返回1184,因为这是显示器的全高(1280像素)减去安卓系统按钮占用的96像素。

最新更新