Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView Position : how can it be a float value ? - Android

I would like to know how it is possible to move a TextView with float values ? We cannot divide a pixel so how is it possible to write something like

TextView t = (TextView)findViewById(R.id.textview);
t.setX(1.5f);
t.setY(1.5f);

? I just don't understand why we can put a float value here.

Thank you

like image 746
Moussamoa Avatar asked Feb 19 '26 03:02

Moussamoa


1 Answers

The preferred geometric unit of measure in Android is dp (Density-independant pixels). The amount of pixels in a dp depends on the screen size of the device used. Using dp instead of actual pixels makes it easier to develop device independant apps.

Therefore, there is not really a reason why you can't have floating point dp!

However, View.setX() is used to set pixels (px), not dp. The only reason I can think of that this takes a floating value is to make convertion between dp and px easier.

However, they are not consistent in this. For example, the method View.setBottom() does take an int instead of a float.

like image 106
wvdz Avatar answered Feb 20 '26 16:02

wvdz



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!