Converting Density Independent Pixels (dp) to Pixels (px) in Android
Sometimes we need to convert density independent pixels(dip/dp) to pixels to set view properties like width or height. Here how it is done using Java.
Resources r = getResources();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, r.getDisplayMetrics());
myEditText.setWidth(px);
Resources r = getResources();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, r.getDisplayMetrics());
myEditText.setWidth(px);
Comments
Post a Comment