Android Pixel to Dip Convert convertPixtoDip(int pixel, Context context)

Here you can find the source of convertPixtoDip(int pixel, Context context)

Description

convert Pixto Dip

Declaration

public static int convertPixtoDip(int pixel, Context context) 

Method Source Code

//package com.java2s;
import android.content.Context;

public class Main {
    public static int convertPixtoDip(int pixel, Context context) {
        float scale = getDensity(context);
        return (int) ((pixel - 0.5f) / scale);
    }/*from w ww  .  j a  v  a  2s . c om*/

    public static float getDensity(Context context) {
        float scale = context.getResources().getDisplayMetrics().density;
        return scale;
    }
}

Related

  1. convertPX2DIP(Context context, float px)
  2. px2dip(Context context, float px)
  3. px2sp(Context context, float pxValue)
  4. getPixelsFromDIP(Context context, int dipValue)
  5. pixel2dip(Context context, float n)