Friday, 15 February 2013

Convert Pixel To Density Pixel

How to convert pixel in desity pixel


in android we need to pass "dp" as parameter of width and height at design time right?
at run time we want to pass value but that will be pass as a "pixel" so that we want to convert that pixel in to density pixel and here is the code to convert pixel in to density pixel.


int pading = 15;

final float SCALE = Activity_Home.this.getResources().getDisplayMetrics().density;

pading  = (int)(pading * SCALE + 0.5f);




form this code we will get 15dp padding to given view.

mdpi:  1dp = 1pxldpi:  1dp = 0.75pxhdpi:  1dp = 1.5pxxhdpi: 1dp = 2px

Call web services easily

get source code from here, Download