Here you can find the source of dpToPx(Context context, int dpValue)
Parameter | Description |
---|---|
context | The context of operation |
dpValue | The dp value to be converted to px |
public static int dpToPx(Context context, int dpValue)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; public class Main { /**/*from w w w . ja v a2 s .c om*/ * Convert dp value to px value * @param context The context of operation * @param dpValue The dp value to be converted to px * @return The px value */ public static int dpToPx(Context context, int dpValue) { DisplayMetrics displayMetrics = context.getResources() .getDisplayMetrics(); return (int) ((dpValue * displayMetrics.density) + 0.5); } }