Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RectF use dp or px?

Tags:

android

canvas

In Canvas, drawing an rectangle with RectF, need set top and left in dp or 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;

http://developer.android.com/intl/es/reference/android/graphics/RectF.html It does not indicate if the values are represented in px or dp.

like image 844
e-info128 Avatar asked Oct 11 '25 10:10

e-info128


1 Answers

As has already been pointed out, Canvas and RectF use px and not dp. As for the documentation, the documentation for Canvas (http://developer.android.com/intl/es/reference/android/graphics/Canvas.html) and RectF only mention pixels.

Since it is not explicitly pointed out that they are dp and both classes are directly derived from java.lang.Object, one can only conclude that it must be "normal" pixels.

If, for some reason, you need to convert from dp to px and vice versa, have a look at this document: http://developer.android.com/intl/es/guide/practices/screens_support.html


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!