使用手机屏幕尺寸的适当方法是什么?

发布于 2025-01-05 23:47:40 字数 330 浏览 0 评论 0原文

以下代码返回屏幕尺寸:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

我正在使用RelativeLayout 来排列内部组件。由于某种原因,当我在组件之间划分宽度(例如 width*30/100width*70/100)时,我会遗漏一些屏幕空间。还有关于高度,如何获取状态栏和标题栏的高度,不同手机之间是否有所不同?

The following code returns the screen size:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

I'm using RelativeLayout to arrange components inside. For some reason when I divide width between components (say width*30/100 and width*70/100) I get some screen space left out. And also about the height how can I get height of status bar and title bar does it vary among phones?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2025-01-12 23:47:40

会对您有所帮助。它指出了状态栏大小的差异。

this would help you. It states the difference in the sizes of status bar.

记忆消瘦 2025-01-12 23:47:40

答案都在此处

快速摘要:Android 根据以下条件向上/向下舍入这些值最接近的支持密度/尺寸比。您可能无法获得所需的准确测量值,具体取决于您的手机。

此外,不推荐使用 Display - 使用 DisplayMetrics

Answer is all in here

Quick summary: Android rounds up/down these values based on the nearest supported density/size ratio. You may not get the exact measurements you want, depending on your phone.

Also, Display is deprecated - use DisplayMetrics

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文