What is the correct way to specify dimensions in DIP from Java code ?
Posted
by Pavel Lahoda
on Stack Overflow
See other posts from Stack Overflow
or by Pavel Lahoda
Published on 2010-02-10T17:22:34Z
Indexed on
2010/04/21
14:43 UTC
Read the original article
Hit count: 358
Trying to digest docs about design Multiple resolutions (http://d.android.com/guide/practices/screens_support.html#dips-pels)
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 relly that formula :
pixels * DisplayMetrics.density = dip
is always correct ? Will there be API in DIPs for Java ?
© Stack Overflow or respective owner