Android Pixel to Dip Convert convertPX2DIP(Context context, float px)

Here you can find the source of convertPX2DIP(Context context, float px)

Description

convert PXDIP

Declaration

public static int convertPX2DIP(Context context, float px) 

Method Source Code

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

public class Main {
    public static int convertPX2DIP(Context context, float px) {
        Resources resources = context.getResources();
        float scale = resources.getDisplayMetrics().density;
        resources = null;//from ww  w.  j a v a  2  s .com
        return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1));
    }
}

Related

  1. getDpFromPixel(float px, Context context)
  2. convertPxtoDp(Context context, int px)
  3. px2dip(Context context, int px)
  4. pixelsAsDp(Context context, int sizeInPx)
  5. pixelsToDpi(Resources res, int pixels)
  6. px2dip(Context context, float px)
  7. px2sp(Context context, float pxValue)
  8. getPixelsFromDIP(Context context, int dipValue)
  9. pixel2dip(Context context, float n)