转换像素DP [英] Converting pixels to dp

查看:138
本文介绍了转换像素DP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了我以像素为单位的泛泰设备,其分辨率为480×800给定的高度和宽度的应用程序。

我需要转换的高度和宽度的G1设备。我想将其转换成DP就能解决问题,并为这两个设备相同的解决方案。

有没有简单的方法来转换像素DP?有什么建议?

解决方案

  /// 14 DIP转换成对应的像素

资源R = getResources();
浮像素= TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,14,r.getDisplayMetrics());
 

I have created my application with the height and width given in pixels for a Pantech device whose resolution is 480x800.

I need to convert height and width for a G1 device. I thought converting it into dp will solve the problem and provide same solution for both devices.

Is there any easy way to convert pixels to dp? Any suggestions?

解决方案

/// Converts 14 dip into its equivalent px

Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());

这篇关于转换像素DP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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