Best Code to convert Pix(Pixel) to Dip(DensityIndependentPixel) value,android

This code i used in LegelPlex Project in "BLCommonOperations.java" file

public int getDip(int pixel)
    {
       
            float scale = SharedVariables.globalContext.getResources().getDisplayMetrics().density;
        int dipvalue=(int) (pixel * scale + 0.5f);
        System.out.println("getDip method???dip???"+dipvalue+"???px value???"+pixel);
            return dipvalue;
     }

Comments

  1. Hi Tilak,

    Its working for me, i tryed so many things but nothing got used for me.
    Thank you very much for your post.

    ReplyDelete

Post a Comment

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard