Is there any way to set the height/width of a LayoutParams as density-independent pixels (dp)? It looks like the height/width, when set programmatically, are in pixels and n
public static int getDPI(int size, DisplayMetrics metrics){
return (size * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
}
Call the function like this,
DisplayMetrics metrics;
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int heigh = getDPI(height or width, metrics);