如何让整个屏幕大小在Android设备上编程屏幕、大小、设备、Android

2023-09-05 00:09:58 作者:玩笑话里藏真心话

如果我在这里使用证明获得整个屏幕大小也总是短暂的身高到整个屏幕大小如图所示的记录规格为设备code。例如,我试图通过使用code,以获得列为1280×800,并从code结果的平板电脑的尺寸,以获得屏幕尺寸:1216 X 800。那么,是丢失的64像素要去?

我可以猜测,这可能是酒吧里保存了回来,家里的按钮在屏幕的底部。但是这听起来权利不为内容的观点应该是所有视图的根。什么是怎么回事?

唯一可能的解释是这部分的用户界面

code用于获取屏幕尺寸

  //获取内容视图窗口的宽度和高度尺寸
   DisplayMetrics displaymetrics =新DisplayMetrics();
   。getWindowManager()getDefaultDisplay()getMetrics(displaymetrics)。
   INT widthContentView = displaymetrics.widthPixels;
   INT heightContentView = displaymetrics.heightPixels;
   Toast.makeText(MainActivity.this,宽内容视图:+ widthContentView Toast.LENGTH_SHORT).show();
   Toast.makeText(MainActivity.this,内容视图的高度:+ heightContentView,Toast.LENGTH_SHORT).show();
 

解决方案 Android系统 Android系统架构简介

如果你调用一个活动的这个之外,你需要传递的情况下(或者通过一些其他的调用得到它)。然后用它来让你的显示器的指标:

  DisplayMetrics指标= context.getResources()getDisplayMetrics()。
INT宽度= metrics.widthPixels;
INT高= metrics.heightPixels;
 

if i use the code shown here to get the total screen size it is always short on height to the total screen size as shown in the documented specs for the device. for example I tried to get the screen size by using the code to get the size for a tablet listed as 1280 X 800 and the result from the code is: 1216 X 800. so where is the missing 64 pixels going to?

i can guess that it could be the bar at the bottom of the screen that holds the back and home buttons. but that does not sound right as the content views is supposed to be the root of all views. what is going on here?

the only possible explanation could be this part of the UI

code used to get screen size

  // gets the content view windows width and height size
   DisplayMetrics displaymetrics = new DisplayMetrics();
   getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
   int widthContentView = displaymetrics.widthPixels;
   int heightContentView = displaymetrics.heightPixels;
   Toast.makeText(MainActivity.this, "width of content view: " + widthContentView  Toast.LENGTH_SHORT).show();
   Toast.makeText(MainActivity.this, "height of content view: " + heightContentView, Toast.LENGTH_SHORT).show();

解决方案

If you're calling this outside of an Activity, you'll need to pass the context in (or get it through some other call). Then use that to get your display metrics:

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;