Android Utililty Methods Display Density Get

List of utility methods to do Display Density Get


The list of methods to do Display Density Get are organized into topic(s).


floatgetDensity(Context context)
get Density
return context.getResources().getDisplayMetrics().density;
intgetDensitySize(Context context, int size)
get Density Size
return (int) getDensity(context) * size;
RectgetBounds(Display d, Rect r)
get Bounds
return new Rect(r.left,, d.getWidth() - r.right,
        d.getHeight() - r.bottom);
floatapplyDimension(int unit, float value, DisplayMetrics metrics)
apply Dimension
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
    return value;
case TypedValue.COMPLEX_UNIT_DIP:
    return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
    return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
device methods
DisplayMetrics displayMetrics = Resources.getSystem()
return (displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f;