简体   繁体   中英

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. Additional ChildViews are added to the RelativeLayout dynamically through onclick events.

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. I have the layout_height set to match_parent however mFrame, which is the RelativeLayout, returns 1184.

Does anyone know why the full length of the display is not being returned when .getHeight() is being called?

The onWindowsChanged() was overridden to detect the screen size of the device being used:

@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:

mDisplayWidth & mDisplayHeight -  w:768 h: 1184

My XML file:

<?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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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