How do I specify that an int
parameter is in dip? Specifically, how would write the equivalent of:
android:layout_width="50dip"
android:layout_height="50dip"
Something like...:
LayoutParams params = new LayoutParams(50, 50)
There is a built-in method that will do this too: TypedValue.applyDimension.
// Convert from 50dip to actual pixels
final int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
final int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
LayoutParams params = new LayoutParams(width, height);
You can use this to convert from sp
units to pixels as well.