int DIP_VALUE = 5;
int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DIP_VALUE, getResources().getDisplayMetrics());
//or simply
float pixels = getResources().getDimensionPixelSize(DIP_VALUE);
mTextView.setTextSize(pixels);
public static float getDipFromPixels(float px) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, Resources.getSystem().getDisplayMetrics());
}
public static float getPixelsFromDip(float dip) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, Resources.getSystem().getDisplayMetrics());
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎