简体   繁体   English

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

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

I am working on an application that has contains a RelativeLayout within the main.xml. 我正在处理在main.xml中包含RelativeLayout的应用程序。 Additional ChildViews are added to the RelativeLayout dynamically through onclick events. 通过onclick事件将其他ChildView动态添加到RelativeLayout中。

When I run the application, the displayHeight retuned for my nexus 4 is 1184 although it should be 1280. Essentially, the height of the screen is being cut short but I don't know why. 当我运行该应用程序时,为我的联系4重新调整的displayHeight是1184,尽管它应该是1280。本质上,屏幕的高度被缩短了,但是我不知道为什么。 I have the layout_height set to match_parent however mFrame, which is the RelativeLayout, returns 1184. 我将layout_height设置为match_parent,但是mFrame(即RelativeLayout)返回1184。

Does anyone know why the full length of the display is not being returned when .getHeight() is being called? 有谁知道为什么在调用.getHeight()时为什么不返回显示的全长?

The onWindowsChanged() was overridden to detect the screen size of the device being used: 重写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);
    }
}

The logcat for this portion of the code returns: 此部分代码的logcat返回:

mDisplayWidth & mDisplayHeight -  w:768 h: 1184

My XML file: 我的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>

The display of the Nexus 4 is 1280 x 768, however the Android system buttons take up part of the screen. Nexus 4的显示为1280 x 768,但是Android系统按钮占据了屏幕的一部分。

Your height returns 1184 as this is the full height of the display (1280 pixels) minus the 96 pixels taken up by the Android system buttons. 您的身高返回1184,因为这是显示屏的全高(1280像素)减去Android系统按钮占用的96像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM