难道setWidth(INT像素)采用DIP或PX? [英] Does setWidth(int pixels) use dip or px?

查看:151
本文介绍了难道setWidth(INT像素)采用DIP或PX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问setWidth(INT像素)使用设备无关像素或物理像素为单位? 例如,是否setWidth(100)设置视图的宽度为100骤降或100 PXS?

Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example, does setWidth(100) set the a view's width to 100 dips or 100 pxs?

感谢。

推荐答案

它使用像素,但我敢肯定你想知道如何使用骤降代替。答案是在<一个href="http://developer.android.com/intl/fr/reference/android/util/TypedValue.html"><$c$c>TypedValue.applyDimension().下面是如何转换逢低code到PX的例子:

It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is in TypedValue.applyDimension(). Here's an example of how to convert dips to px in code:

// Converts 14 dip into its equivalent px
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());

这篇关于难道setWidth(INT像素)采用DIP或PX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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