GetWindowVisibleDisplayFrame () gives different values ​​in Android 2.2, 2.3 (but not 2.3.3)

I have Activitythat uses

getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);

to determine the usable screen space and decide where to place the images.

Returning to Activity after I press the back button to leave the Activityrectangle values

(0,0,800,480)

However, returning to Activity after I press the "home" button at the hardware level to leave Activity, the values ​​of the rectangle

(0,38,800,480)

which discards the display and image placement.

How can I provide consistent values ​​when called

getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);

no matter how i left the application?

UPDATE: Thanks @Reno for the help in testing; it seems to depend on the version of Android than on the device.

+5
4

Welp, , ,

    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;
    }

outRect.top < 2.3.3

+4

, , . getWindowVisibleDisplayFrame, .

+1

, :

    Rect rectangle = new Rect();
    getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
    if(android.os.Build.VERSION.SDK_INT < 9  /* android.os.Build.VERSION_CODES.GINGERBREAD */ ) {
        // http://stackoverflow.com/questions/7659652/getwindowvisibledisplayframe-gives-different-values-in-android-2-2-2-3-but-no/7660204#7660204
        rectangle.top = 0;
    }
0

There are times when you need to know the exact size of the available space for the layout when onCreate is in action. After thinking, I decided to do this: fooobar.com/questions/624 / ... It does not use getWindowVisibleDisplayFrame and, hopefully, will be proof in the future.

0
source

All Articles