有没有办法让dpi的屏幕尺寸 [英] Is there a way to get screen size in dpi

查看:276
本文介绍了有没有办法让dpi的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这样的:

  INT无线= getWindowManager()getDefaultDisplay()的getWidth()。

获取屏幕尺寸以像素为单位。有没有办法让 dpi的屏幕尺寸 ???

我在做这个选择屏幕尺寸不同布局的基础。


解决方案

  

有没有办法让以dpi为escreen大小???


DisplayMetrics 可以告诉你,在像素的屏幕尺寸,加上屏幕密度。从那里,你可以在 DP 计算的屏幕尺寸。


  

我在做这个选择屏幕尺寸不同布局的基础。


这是自动为您的资源框架来处理,如果你把你的布局在正确的目录(例如, RES /布局大/ RES /布局sw600dp / )。

I'm using this:

int wi=getWindowManager().getDefaultDisplay().getWidth();

to get the screen size in pixels. Is there a way to get the screen size in dpi???

I'm doing this to select different layouts base on the screen size.

解决方案

Is there a way to get the escreen size in dpi???

DisplayMetrics can tell you the screen size in pixels, plus the screen density. From there, you can calculate the screen size in dp.

I'm doing this to select different layouts base on the screen size.

This is automatically handled for you by the resource framework, if you put your layouts in the proper directories (e.g., res/layout-large/, res/layout-sw600dp/).

这篇关于有没有办法让dpi的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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