Android Dip to Pixel Convert convertDpToPixel(float dp, Context context)

Here you can find the source of convertDpToPixel(float dp, Context context)

Description

convert Dp To Pixel

Declaration

public static float convertDpToPixel(float dp, Context context) 

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 convertDpToPixel(float dp, Context context) {
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        float px = dp * (metrics.densityDpi / 160f);
        return px;
    }//from  w w  w.  j  av  a 2  s.c  om
}

Related

  1. dipToPixel(int dip)
  2. dipsToPixels(Context aContext, int aDip)
  3. convertDIP2PX(Context context, float dip)
  4. sp2px(Context context, float spValue)
  5. scaleDpToPixels(double value, Resources res)
  6. convertDpToPixel(float dp, Resources resources)
  7. dipToPixels(int dip)
  8. sp2px(Context context, float spValue)
  9. sp2px(float sp, Context context)