I found that it is possible to set dimensions of my interface elements in XML layouts using DIPs as in following fragment:
android:layout_width="10dip"
But all Java interface takes integer as arguments and there is no way to specify dimensions in DIPs. What is the correct way to calculate this?
I figured that I have to use property density of DisplayMetrics
class but is this a correct way?
May I rely on this formula being always correct?
pixels * DisplayMetrics.density = dip
Is there a utility function for the conversion somewhere in Android?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…