Android Pixel to Dip Convert convertPixelsToDp(Context context, float pxValue)

Here you can find the source of convertPixelsToDp(Context context, float pxValue)

Description

convert Pixels To Dp

Declaration

public static float convertPixelsToDp(Context context, float pxValue) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.content.res.Resources;

import android.util.DisplayMetrics;

public class Main {
    public static float convertPixelsToDp(Context context, float pxValue) {
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        return pxValue / (metrics.densityDpi / 160f);

    }/*from  www. j  ava 2 s.c o m*/
}

Related

  1. convertPixelsToDp(Context ctx, float px)
  2. convertPixelsToSp(Context context, float pxValue)
  3. px2dip(Context context, float pxValue)
  4. px2dip(Context context, float pxValue)