【发布时间】:2016-03-03 19:12:43
【问题描述】:
我想获取运行我的应用的设备的实际屏幕高度。为此,我尝试以下方法:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int Height = metrics.heightPixels;
TextView HeightView = (TextView) findViewById(R.id.screenHeight);
HeightView.setText("Screen Height: " + Height);
int Width = metrics.widthPixels;
TextView WidthView = (TextView) findViewById(R.id.screenWidth);
WidthView.setText("Screen Width: " + Width);
我使用模拟器运行的设备的屏幕宽度为 1080 像素,屏幕高度为 1920 像素。宽度显示正确(1080 像素),但高度根据应用程序只有 1776 像素。我需要什么才能让我的应用显示正确的屏幕高度? metrics.heightPixels 是不是获取屏幕高度的坏方法?
【问题讨论】:
标签: java android android-studio