Posts

Showing posts with the label screen size

how to scale font size for different screen size in android?

Scale font size for different support device Different screen density using the following size scale: xxxhdpi : 4.0 xxhdpi : 3.0 xhdpi : 2.0 hdpi : 1.5 mdpi : 1.0 (baseline) ldpi : 0.75 A set of six generalized  densities : ldpi  (low) ~120dpi mdpi  (medium) ~160dpi hdpi  (high) ~240dpi xhdpi  (extra-high) ~320dpi xxhdpi  (extra-extra-high) ~480dpi xxxhdpi  (extra-extra-extra-high) ~640dpi Below function use for convert dp(Density indipendent pixel) to PX. public static int dp2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } Now We are going to set dynamic font size for all device  Note: It will work only on the device, not on the tablet. we need to write different logic for the tablet. textView.setTextSize(TypedValue. COMPLEX_UNIT_PX , dp2px ( this , 12f )); How It works on different screen....