RectF使用dp还是px?

4
在Canvas中,使用RectF绘制矩形时,需要将top和left设置为dp或px单位?
Integer padding = 10;
Integer width = 100; // It is dp or px?
Integer height = 50;

RectF position = new RectF();
position.top = 0 + padding;
position.bottom = position.top + height;
position.left = 0 + padding;
position.right = position.left + width;

它没有说明这些值是以像素(px)还是密度无关像素(dp)表示的。

http://developer.android.com/intl/es/reference/android/graphics/RectF.html


3
画布(canvas)始终使用 px (像素)。 - Phantômaxx
它在哪里有记录? - e-info128
3个回答

7

0

它使用像素,而不是密度无关像素。


谢谢,那个文档在哪里定义? - e-info128
不确定。Android中的大多数图形API都使用像素。 - Alex Lockwood

0

它使用像素,但如果您想要,必须进行转换。

private int convertDpToPx(int dp){
    return Math.round(dp * (getResources().getDisplayMetrics().xdpi / DisplayMetrics.DENSITY_DEFAULT));
}

希望它有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接