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\"
>
That is the correct formula there. Although DisplayMetrics.density
is not a static member, so, according to the same document you alluded to, correct usage is:
// Maybe store this in a static field?
final float SCALE = getContext().getResources().getDisplayMetrics().density;
// Convert dips to pixels
float valueDips = 16.0f;
int valuePixels = (int)(valueDips * SCALE + 0.5f); // 0.5f for rounding