简体   繁体   English

Android Point对象澄清

[英]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? 我知道一点基本上只包含两点,代表位置的x和y整数,但是它们实际经过的单位是什么?

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) . 我假设像素只是因为当我使用显示对象获取默认电话屏幕的大小并将其存储在点对象(display.getSize(point))并记录了我的点对象时,我得到了(720, 1184)

It can't be dps or anything like that because only pixels are can be that large. 不能是dps或类似的东西,因为只有像素可以那么大。 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. 但是,当我尝试将720px作为随机UI元素的宽度进行测试时,由于无法填满手机的整个宽度,因此大约减少了40像素。 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. 所以我想知道为什么当我的手机宽度稍大于720px时返回720px。

If I did have padding, would display.getSize() take this into account? 如果我确实有填充,那么display.getSize()考虑到这一点吗?

Short answer(s) : 简短答案

what units do they actually go by? 他们实际经过什么单位?

Point can represent different things but after display.getSize() call it is pixels. 点可以表示不同的事物,但是在display.getSize()调用之后,它是像素。

why it returned 720px when my phone width is a bit larger than that. 为什么当我的手机宽度稍大于720px时返回720px

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() 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? 如果我确实有填充,那么display.getSize()会考虑到这一点吗?

Yes. 是。

Longer Answer : According to the API docos : 更长的答案 :根据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). 使用以下方法查询应用程序显示区域:getSize(Point),getRectSize(Rect)和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). 即使这样,如果窗口管理器正在使用(adb shell am display-size)模拟较小的显示,则实际显示区域可能小于显示器的物理尺寸。 Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics). 使用以下方法查询实际显示区域: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 : 再次从docos

void getSize (Point outSize) 无效的getSize(点outSize)

Gets the size of the display, in pixels. 获取显示的大小,以像素为单位。

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

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