Moussamoa
Moussamoa

Reputation: 427

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

Upvotes: 3

Views: 851

Answers (1)

wvdz
wvdz

Reputation: 16651

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.

Upvotes: 2

Related Questions