简体   繁体   中英

Android Point object clarification

I know that a point basically just holds two things, an x and y integer which represents location, but what units do they actually go by?

I'm assuming pixels just because when I used a display object to get the size of my default phone screen and store it in a point object (display.getSize(point)) and logged my point object, I got (720, 1184) .

It can't be dps or anything like that because only pixels are can be that large. However, when I tried testing the 720px as the width for a random UI element, it fell about 40 pixels short from filling the entire width of my phone. I had no padding in this activity either. So I'm wondering why it returned 720px when my phone width is a bit larger than that.

If I did have padding, would display.getSize() take this into account?

Short answer(s) :

what units do they actually go by?

Point can represent different things but after display.getSize() call it is pixels.

why it returned 720px when my phone width is a bit larger than that.

Padding, System decor, compatibility issues, Window Manager issues. You can also get a different answer from:

getApplicationContext().getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getSize(point)

and

getWindowManager().getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getSize()

And this can also be effected if the application/device is running in multi-window mode.

If I did have padding, would display.getSize() take this into account?

Yes.

Longer Answer : According to the API docos :

The application display area specifies the part of the display that may contain an application window, excluding the system decorations. The application display area may be smaller than the real display area because the system subtracts the space needed for decor elements such as the status bar. Use the following methods to query the application display area: getSize(Point), getRectSize(Rect) and getMetrics(DisplayMetrics).

The real display area specifies the part of the display that contains content including the system decorations. Even so, the real display area may be smaller than the physical size of the display if the window manager is emulating a smaller display using (adb shell am display-size). Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics).

So most likely you want to use

getRealSize(Point);

To get the amount of space. As to your question about the Point units, I believe it is actually pixels. Again from the docos :

void getSize (Point outSize)

Gets the size of the display, in pixels.

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