使用手机屏幕尺寸的适当方法是什么?
以下代码返回屏幕尺寸:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
我正在使用RelativeLayout 来排列内部组件。由于某种原因,当我在组件之间划分宽度(例如 width*30/100
和 width*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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这会对您有所帮助。它指出了状态栏大小的差异。
this would help you. It states the difference in the sizes of status bar.
答案都在此处
快速摘要: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