难道setWidth(INT像素)采用DIP或PX?像素、INT、setWidth、DIP

由网友(十里无你)分享简介:请问setWidth(INT像素)使用设备无关像素或物理像素为单位?例如,是否setWidth(100)设置视图的宽度为100骤降或100 PXS?Does setWidth(int pixels) use device independent pixel or physical pixel as unit?Fo...

请问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?

感谢。

推荐答案

它使用像素,但我敢肯定你想知道如何使用骤降代替。答案是在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());
阅读全文

相关推荐

最新文章