如何获得设备的屏幕大小? [英] How to get screen size of device?

查看:136
本文介绍了如何获得设备的屏幕大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一款Android屏幕的高度,如果屏幕出师表一定的高度,我怎么会去这样做?

I would like to get the height of a android screen and if the screen inst a certain height, how would i go about doing this?

推荐答案

如果你想在像素的显示尺寸,你可以使用这个code:

If you want the display dimensions in pixels you can use this code:

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

然后,您可以添加条件比较高,以满足您的需求。

Then you can add condition that compares the height to satisfy your needs.

在英寸:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
Log.d("debug","Screen inches : " + screenInches);

这篇关于如何获得设备的屏幕大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆