Pixel to density independent pixel to pixel conversion

Physical pixel (px)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)

public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
 
public static int pxToDp(int px)
{
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
This entry was posted in Android Examples Code and tagged . Bookmark the permalink.


Comments are closed.



1,016 views